@vbarbarosh/node-helpers 3.5.2 → 3.5.3
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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@vbarbarosh/node-helpers",
|
|
5
|
-
"version": "3.5.
|
|
5
|
+
"version": "3.5.3",
|
|
6
6
|
"description": "A set of helpers for JavaScript/Node.js",
|
|
7
7
|
"files": [
|
|
8
8
|
"src"
|
|
@@ -27,14 +27,15 @@
|
|
|
27
27
|
"bluebird": "^3.7.2",
|
|
28
28
|
"form-data": "^4.0.0",
|
|
29
29
|
"json-stable-stringify": "^1.0.2",
|
|
30
|
-
"sanitize-filename": "^1.6.3"
|
|
30
|
+
"sanitize-filename": "^1.6.3",
|
|
31
|
+
"split": "^1.0.1"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"mocha": "^10.2.0",
|
|
34
|
-
"throttle": "^1.0.3",
|
|
35
35
|
"redis-v1": "npm:redis@1",
|
|
36
36
|
"redis-v2": "npm:redis@2",
|
|
37
37
|
"redis-v3": "npm:redis@3",
|
|
38
|
-
"redis-v4": "npm:redis@4"
|
|
38
|
+
"redis-v4": "npm:redis@4",
|
|
39
|
+
"throttle": "^1.0.3"
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -2,10 +2,10 @@ const axios = require('axios');
|
|
|
2
2
|
const format_thousands = require('./format_thousands');
|
|
3
3
|
const parse_http_content_range = require('./parse_http_content_range');
|
|
4
4
|
|
|
5
|
-
async function http_get_stream_range(url,
|
|
5
|
+
async function http_get_stream_range(url, first, last)
|
|
6
6
|
{
|
|
7
|
-
const a = Number.isInteger(
|
|
8
|
-
const b = Number.isInteger(
|
|
7
|
+
const a = Number.isInteger(first) ? first : '';
|
|
8
|
+
const b = Number.isInteger(last) ? last : '';
|
|
9
9
|
const headers = {Range: `bytes=${a}-${b}`};
|
|
10
10
|
const res = await axios.get(url, {responseType: 'stream', headers});
|
|
11
11
|
const out = res.data;
|
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
const assert = require('assert');
|
|
2
2
|
const fs = require('fs');
|
|
3
|
+
const split = require('split');
|
|
4
|
+
const stream = require('stream');
|
|
3
5
|
const stream_data_ln = require('./stream_data_ln');
|
|
4
6
|
const stream_promise = require('./stream_promise');
|
|
5
7
|
|
|
6
8
|
describe('stream_data_ln', function () {
|
|
7
9
|
it('should handle basic input', async function () {
|
|
8
|
-
let
|
|
10
|
+
let actual = '';
|
|
9
11
|
const s = fs.createReadStream(__filename);
|
|
10
|
-
const off = stream_data_ln(s, v =>
|
|
12
|
+
const off = stream_data_ln(s, v => actual += v + '\n');
|
|
11
13
|
await stream_promise(s);
|
|
12
14
|
off();
|
|
13
|
-
assert.deepStrictEqual(
|
|
15
|
+
assert.deepStrictEqual(actual, fs.readFileSync(__filename, {encoding: 'utf8'}));
|
|
16
|
+
});
|
|
17
|
+
it('split', async function () {
|
|
18
|
+
let actual = '';
|
|
19
|
+
const s = fs.createReadStream(__filename);
|
|
20
|
+
const ss = s.pipe(split('\n', null, {trailing: false}));
|
|
21
|
+
ss.on('data', v => actual += v + '\n');
|
|
22
|
+
await stream.promises.finished(ss);
|
|
23
|
+
assert.deepStrictEqual(actual, fs.readFileSync(__filename, {encoding: 'utf8'}));
|
|
14
24
|
});
|
|
15
25
|
});
|