@abtnode/util 1.16.8-beta-186fd5aa → 1.16.8-beta-7d175032

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.
@@ -51,7 +51,7 @@ async function streamToString(stream) {
51
51
  * @param {{}} context
52
52
  * @return {*}
53
53
  */
54
- const downloadFile = async (url, dest, { timeout = 600 * 1000, cancelCtrl } = {}, context = {}) => {
54
+ const downloadFile = async (url, dest, { timeout = 600 * 1000, cancelCtrl, onProgress } = {}, context = {}) => {
55
55
  const CONNECTION_TIMEOUT = 20 * 1000;
56
56
  const source = CancelToken.source();
57
57
 
@@ -83,6 +83,20 @@ const downloadFile = async (url, dest, { timeout = 600 * 1000, cancelCtrl } = {}
83
83
  cancelToken: source.token,
84
84
  timeout,
85
85
  });
86
+
87
+ if (typeof onProgress === 'function') {
88
+ const total = (response.headers || {})['content-length'] || 0;
89
+ let current = 0;
90
+ response.data.on('data', (chunk) => {
91
+ current += chunk.length;
92
+ try {
93
+ onProgress({ total, current });
94
+ } catch {
95
+ // do nothing
96
+ }
97
+ });
98
+ }
99
+
86
100
  clearTimeout(timer);
87
101
  fileStream = response.data.pipe(fs.createWriteStream(dest));
88
102
  await streamToPromise(fileStream);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.8-beta-186fd5aa",
6
+ "version": "1.16.8-beta-7d175032",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,13 +18,13 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.16.8-beta-186fd5aa",
22
- "@abtnode/logger": "1.16.8-beta-186fd5aa",
23
- "@blocklet/constant": "1.16.8-beta-186fd5aa",
24
- "@ocap/client": "1.18.78",
25
- "@ocap/mcrypto": "1.18.78",
26
- "@ocap/util": "1.18.78",
27
- "@ocap/wallet": "1.18.78",
21
+ "@abtnode/constant": "1.16.8-beta-7d175032",
22
+ "@abtnode/logger": "1.16.8-beta-7d175032",
23
+ "@blocklet/constant": "1.16.8-beta-7d175032",
24
+ "@ocap/client": "1.18.80",
25
+ "@ocap/mcrypto": "1.18.80",
26
+ "@ocap/util": "1.18.80",
27
+ "@ocap/wallet": "1.18.80",
28
28
  "archiver": "^5.3.1",
29
29
  "axios": "^0.27.2",
30
30
  "axios-mock-adapter": "^1.21.2",
@@ -71,5 +71,5 @@
71
71
  "jest": "^27.5.1",
72
72
  "unzipper": "^0.10.11"
73
73
  },
74
- "gitHead": "3150c3a5c3e041fe7f5a3902418d9d62adee3173"
74
+ "gitHead": "681bf5cac8fc4c4b90c64ad4c6a4faaa99a81f97"
75
75
  }