@vbarbarosh/node-helpers 3.24.0 → 3.24.1

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.24.0",
5
+ "version": "3.24.1",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
package/src/fastdl.js CHANGED
@@ -3,6 +3,7 @@ const format_progress = require('./format_progress');
3
3
  const format_thousands = require('./format_thousands');
4
4
  const fs = require('fs');
5
5
  const fs_path_basename = require('./fs_path_basename');
6
+ const ignore = require('./ignore');
6
7
  const make_progress = require('./make_progress');
7
8
  const parallel = require('./parallel');
8
9
  const stream = require('stream');
@@ -37,6 +38,7 @@ async function fastdl({file, read_stream_with_range, concurrency = 60, user_frie
37
38
 
38
39
  const timer = setInterval(tick, 1000);
39
40
  function tick() {
41
+ progress.refresh();
40
42
  user_friendly_status(`${format_progress(progress)} connections=${connections}`);
41
43
  }
42
44
 
@@ -68,6 +70,11 @@ async function fastdl({file, read_stream_with_range, concurrency = 60, user_frie
68
70
  return;
69
71
  }
70
72
  const rs = (first === 0) ? rs0 : await read_stream_with_range(first, last);
73
+ if (rs.content_range.total !== total) {
74
+ rs.once('error', ignore);
75
+ rs.destroy();
76
+ throw new Error('Size of a file changed during download');
77
+ }
71
78
  const acc = new stream.PassThrough({
72
79
  transform(buf, encoding, next) {
73
80
  first += buf.length;
@@ -2,8 +2,6 @@ const ignore = require('./ignore');
2
2
  const ssh2 = require('ssh2');
3
3
  const waitcb = require('./waitcb');
4
4
 
5
- const ___stat = Symbol('sftp_get_stream_range.stat');
6
-
7
5
  async function sftp_get_stream_range(url, first, last, {log = ignore} = {})
8
6
  {
9
7
  const u = new URL(url);
@@ -25,7 +23,7 @@ async function sftp_get_stream_range(url, first, last, {log = ignore} = {})
25
23
  const sftp = await waitcb(cb => conn.sftp(cb));
26
24
 
27
25
  log('Requesting file info...');
28
- const stat = url[___stat] || (url[___stat] = await waitcb(cb => sftp.stat(pathname, cb)));
26
+ const stat = await waitcb(cb => sftp.stat(pathname, cb));
29
27
 
30
28
  if (first < 0 || last >= stat.size) {
31
29
  throw new Error(`Invalid range: [first=${first}][last=${last}]`);