diff --git a/download.js b/download.js index 33c4be1..f3acea8 100644 --- a/download.js +++ b/download.js @@ -18,7 +18,6 @@ const fsp = require('fs').promises; const path = require('path'); const { URL } = require('url'); const contentDisposition = require('content-disposition'); -const archiveType = require('archive-type'); const decompress = require('decompress'); const filenamify = require('filenamify'); const getStream = require('get-stream'); @@ -28,6 +27,14 @@ const pEvent = require('p-event'); const FileType = require('file-type'); const extName = require('ext-name'); +// This function is inspired by now abandoned module from https://github.com/kevva/archive-type repository +const archiveTypeFromBuffer = async (input) => { + const archiveExtensions = new Set(['7z', 'bz2', 'gz', 'rar', 'tar', 'zip', 'xz', 'gz']); + + const ret = await FileType.fromBuffer(input); + return archiveExtensions.has(ret && ret.ext) ? ret : null; +}; + const filenameFromPath = (res) => path.basename(new URL(res.requestUrl).pathname); const getExtFromMime = (res) => { @@ -97,13 +104,13 @@ module.exports = (uri, output, opts) => { const [data, res] = result; if (!output) { - return opts.extract && archiveType(data) ? decompress(data, opts) : data; + return opts.extract && (await archiveTypeFromBuffer(data)) ? decompress(data, opts) : data; } const filename = opts.filename || filenamify(await getFilename(res, data)); const outputFilepath = path.join(output, filename); - if (opts.extract && archiveType(data)) { + if (opts.extract && (await archiveTypeFromBuffer(data))) { return decompress(data, path.dirname(outputFilepath), opts); } diff --git a/package.json b/package.json index 6b75a62..390a03e 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "homepage": "https://github.com/serverless/utils#readme", "author": "Serverless, Inc.", "dependencies": { - "archive-type": "^4.0.0", "chalk": "^4.1.2", "ci-info": "^3.3.2", "cli-progress-footer": "^2.3.2", @@ -16,7 +15,7 @@ "event-emitter": "^0.3.5", "ext": "^1.6.0", "ext-name": "^5.0.0", - "file-type": "^16.5.3", + "file-type": "^16.5.4", "filenamify": "^4.3.0", "get-stream": "^6.0.1", "got": "^11.8.5",