@vbarbarosh/node-helpers 3.47.2 → 3.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @link https://github.com/jshttp/range-parser
|
|
3
|
+
*/
|
|
4
|
+
function http_range_parse(range, total)
|
|
5
|
+
{
|
|
6
|
+
const m = range.match(/^bytes\s*=\s*(\d*)-(\d*)$/);
|
|
7
|
+
|
|
8
|
+
if (!m || (!m[1] && !m[2])) {
|
|
9
|
+
throw new Error(`Cannot parse range "${range}". Only "bytes=FIRST-LAST", "bytes=FIRST-", or "bytes=-LAST" are supported.`);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let first = +m[1];
|
|
13
|
+
let last = +m[2];
|
|
14
|
+
|
|
15
|
+
if (!m[1]) { // -LAST
|
|
16
|
+
first = total - last;
|
|
17
|
+
last = total - 1;
|
|
18
|
+
}
|
|
19
|
+
else if (!m[2]) { // FIRST-
|
|
20
|
+
last = total - 1;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (first < 0 || first > last || first >= total || last < 0 || last < first || last >= total) {
|
|
24
|
+
throw new Error(`Invalid range: first=${first}, last=${last}, total=${total}, expr="${range}"`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {first, last};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = http_range_parse;
|
|
@@ -6,10 +6,10 @@ const stream_map_parallel = require('./stream_map_parallel');
|
|
|
6
6
|
|
|
7
7
|
describe('stream_map_parallel', function () {
|
|
8
8
|
it('basic', async function () {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const actual = [];
|
|
10
|
+
const expected = Array(100).fill().map((v,i) => i);
|
|
11
11
|
await stream.promises.pipeline(
|
|
12
|
-
stream.Readable.from(
|
|
12
|
+
stream.Readable.from(expected),
|
|
13
13
|
stream_map_parallel({
|
|
14
14
|
concurrency: 5,
|
|
15
15
|
handler: async function (num) {
|
|
@@ -18,9 +18,9 @@ describe('stream_map_parallel', function () {
|
|
|
18
18
|
},
|
|
19
19
|
}),
|
|
20
20
|
stream_each(function (item) {
|
|
21
|
-
|
|
21
|
+
actual.push(item);
|
|
22
22
|
}),
|
|
23
23
|
);
|
|
24
|
-
assert.deepStrictEqual(
|
|
24
|
+
assert.deepStrictEqual(actual, expected);
|
|
25
25
|
});
|
|
26
26
|
});
|