@expo/downloader
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -7,13 +7,14 @@ "use strict"; | ||
const fs_1 = __importDefault(require("fs")); | ||
const got_1 = __importDefault(require("got")); | ||
const stream_1 = __importDefault(require("stream")); | ||
const util_1 = require("util"); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const pipeline = util_1.promisify(stream_1.default.pipeline); | ||
async function downloadFile(srcUrl, outputPath, timeout) { | ||
const writeStream = fs_1.default.createWriteStream(outputPath); | ||
const stream = got_1.default.stream(srcUrl, { timeout }); | ||
stream.pipe(writeStream); | ||
await new Promise((res, rej) => { | ||
stream.on('end', () => res()); | ||
stream.on('error', (err) => rej(err)); | ||
}); | ||
const res = await node_fetch_1.default(srcUrl, { timeout }); | ||
if (res.status !== 200) { | ||
throw new Error(`Failed to download the file, status code: ${res.status}`); | ||
} | ||
await pipeline(res.body, fs_1.default.createWriteStream(outputPath)); | ||
} | ||
exports.default = downloadFile; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@expo/downloader", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "dist/index.js", | ||
@@ -16,2 +16,3 @@ "types": "dist/index.d.ts", | ||
"compile": "tsc -p tsconfig.build.json", | ||
"prepublishOnly": "npm run build", | ||
"lint": "eslint 'src/**/*.ts'", | ||
@@ -21,7 +22,6 @@ "test": "yarn run jest" | ||
"dependencies": { | ||
"got": "^10.6.0" | ||
"node-fetch": "^2.6.0" | ||
}, | ||
"devDependencies": { | ||
"@types/bunyan": "^1.8.6", | ||
"@types/got": "^9.6.9", | ||
"@types/node-fetch": "^2.5.5", | ||
"@typescript-eslint/eslint-plugin": "^2.11.0", | ||
@@ -28,0 +28,0 @@ "@typescript-eslint/parser": "^2.11.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10
20
165639
+ Addednode-fetch@^2.6.0
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
- Removedgot@^10.6.0
- Removed@sindresorhus/is@2.1.1(transitive)
- Removed@szmarczak/http-timer@4.0.6(transitive)
- Removed@types/cacheable-request@6.0.3(transitive)
- Removed@types/http-cache-semantics@4.0.4(transitive)
- Removed@types/keyv@3.1.4(transitive)
- Removed@types/node@22.10.2(transitive)
- Removed@types/responselike@1.0.3(transitive)
- Removedcacheable-lookup@2.0.1(transitive)
- Removedcacheable-request@7.0.4(transitive)
- Removedclone-response@1.0.3(transitive)
- Removeddecompress-response@5.0.0(transitive)
- Removeddefer-to-connect@2.0.1(transitive)
- Removedduplexer3@0.1.5(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedget-stream@5.2.0(transitive)
- Removedgot@10.7.0(transitive)
- Removedhttp-cache-semantics@4.1.1(transitive)
- Removedjson-buffer@3.0.1(transitive)
- Removedkeyv@4.5.4(transitive)
- Removedlowercase-keys@2.0.0(transitive)
- Removedmimic-response@1.0.12.1.0(transitive)
- Removednormalize-url@6.1.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-cancelable@2.1.1(transitive)
- Removedp-event@4.2.0(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedp-timeout@3.2.0(transitive)
- Removedpump@3.0.2(transitive)
- Removedresponselike@2.0.1(transitive)
- Removedto-readable-stream@2.1.0(transitive)
- Removedtype-fest@0.10.0(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedwrappy@1.0.2(transitive)