@vbarbarosh/node-helpers 3.24.0 → 3.25.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
package/src/errors/AbortError.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
const UserFriendlyError = require('./UserFriendlyError');
|
|
2
|
+
|
|
1
3
|
// https://github.com/nodejs/node/issues/36084#issuecomment-729894622
|
|
2
|
-
class AbortError extends
|
|
4
|
+
class AbortError extends UserFriendlyError
|
|
3
5
|
{
|
|
4
6
|
constructor(message = 'The operation was aborted') {
|
|
5
7
|
super(message);
|
package/src/fastdl.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
const UserFriendlyError = require('./errors/UserFriendlyError');
|
|
1
2
|
const format_bytes = require('./format_bytes');
|
|
2
3
|
const format_progress = require('./format_progress');
|
|
3
4
|
const format_thousands = require('./format_thousands');
|
|
4
5
|
const fs = require('fs');
|
|
5
6
|
const fs_path_basename = require('./fs_path_basename');
|
|
7
|
+
const ignore = require('./ignore');
|
|
6
8
|
const make_progress = require('./make_progress');
|
|
7
9
|
const parallel = require('./parallel');
|
|
8
10
|
const stream = require('stream');
|
|
@@ -37,6 +39,7 @@ async function fastdl({file, read_stream_with_range, concurrency = 60, user_frie
|
|
|
37
39
|
|
|
38
40
|
const timer = setInterval(tick, 1000);
|
|
39
41
|
function tick() {
|
|
42
|
+
progress.refresh();
|
|
40
43
|
user_friendly_status(`${format_progress(progress)} connections=${connections}`);
|
|
41
44
|
}
|
|
42
45
|
|
|
@@ -51,7 +54,7 @@ async function fastdl({file, read_stream_with_range, concurrency = 60, user_frie
|
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
if (total !== total_written) {
|
|
54
|
-
throw new
|
|
57
|
+
throw new UserFriendlyError(`Total bytes written differs from expected size of a file: total[${total}] - total_written[${total_written}] = ${total - total_written}`);
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
function spawn() {
|
|
@@ -68,6 +71,11 @@ async function fastdl({file, read_stream_with_range, concurrency = 60, user_frie
|
|
|
68
71
|
return;
|
|
69
72
|
}
|
|
70
73
|
const rs = (first === 0) ? rs0 : await read_stream_with_range(first, last);
|
|
74
|
+
if (rs.content_range.total !== total) {
|
|
75
|
+
rs.once('error', ignore);
|
|
76
|
+
rs.destroy();
|
|
77
|
+
throw new UserFriendlyError('Size of a file changed during download');
|
|
78
|
+
}
|
|
71
79
|
const acc = new stream.PassThrough({
|
|
72
80
|
transform(buf, encoding, next) {
|
|
73
81
|
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 =
|
|
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}]`);
|