@vbarbarosh/node-helpers 3.23.2 → 3.23.4

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.23.2",
5
+ "version": "3.23.4",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
package/src/fastdl.js CHANGED
@@ -58,18 +58,19 @@ async function fastdl({file, read_stream_with_range, concurrency = 60, user_frie
58
58
  if (next_first >= total) {
59
59
  return;
60
60
  }
61
- const first = next_first;
61
+ let first = next_first;
62
62
  const last = Math.min(total - 1, first + (first === 0 ? rs0.content_range.last : chunk_size));
63
63
  next_first = last + 1;
64
64
  connections++;
65
- return Promise.resolve(run()).finally(() => connections--);
65
+ return Promise.resolve(run()).catch(run).catch(run).finally(() => connections--);
66
66
  async function run() {
67
67
  const rs = (first === 0) ? rs0 : await read_stream_with_range(first, last);
68
68
  const acc = new stream.PassThrough({
69
- transform(buf, enc, cb) {
69
+ transform(buf, encoding, next) {
70
+ first += buf.length;
70
71
  total_written += buf.length;
71
72
  progress.add(buf.length);
72
- cb(null, buf);
73
+ next(null, buf);
73
74
  }
74
75
  });
75
76
  const ws = fs.createWriteStream(file, {
@@ -2,13 +2,18 @@ const assert = require('assert');
2
2
  const make_number = require('./make_number');
3
3
 
4
4
  const items = [
5
- ['-inf → 0', -Infinity, 0],
6
- ['+inf → 0', +Infinity, 0],
7
5
  ['null → 0', null, 0],
6
+ ['undefined → 0', undefined, 0],
8
7
  ['{} → 0', {}, 0],
8
+ ['nan → 0', NaN, 0],
9
+ ['-inf → 0', -Infinity, 0],
10
+ ['+inf → 0', +Infinity, 0],
11
+ ['false → 0', false, 0],
12
+ ['true → 1', true, 1],
9
13
  ['Symbol() → 0', Symbol(), 0],
10
14
  ['Function → 0', () => 1, 0],
11
15
  ['BigInt(1) → 1', 1n, 1],
16
+ ['"123" → 123', '123', 123],
12
17
  ];
13
18
 
14
19
  describe('make_number', function () {
@@ -38,8 +38,11 @@ async function sftp_get_stream_range(url, first, last, {log = ignore} = {})
38
38
  last,
39
39
  total: stat.size,
40
40
  };
41
+ out.once('error', function () {
42
+ conn.destroy();
43
+ });
41
44
  out.once('end', function () {
42
- conn.end();
45
+ conn.destroy();
43
46
  });
44
47
  return out;
45
48
  }