From 65c5fe5798e7a45f08efc4ab0652db8e63e695fe Mon Sep 17 00:00:00 2001 From: Leo Nesfield Date: Thu, 20 Aug 2020 19:34:17 +0100 Subject: [PATCH 1/3] only attempt to open a file if it's a string --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 23384ea..e4092f4 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ const stream = require('stream') const yauzl = require('yauzl') const openZip = promisify(yauzl.open) +const openBuffer = promisify(yauzl.fromBuffer) const pipeline = promisify(stream.pipeline) class Extractor { @@ -19,7 +20,7 @@ class Extractor { async extract () { debug('opening', this.zipPath, 'with opts', this.opts) - this.zipfile = await openZip(this.zipPath, { lazyEntries: true }) + this.zipfile = await (typeof this.zipPath == "string" ? openZip : openBuffer)(this.zipPath, { lazyEntries: true }) this.canceled = false return new Promise((resolve, reject) => { From d50d66591af855bb1df8950402cb9e71f4348dab Mon Sep 17 00:00:00 2001 From: Leo Nesfield Date: Thu, 20 Aug 2020 19:43:24 +0100 Subject: [PATCH 2/3] Make the linter happy --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e4092f4..fb26019 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ class Extractor { async extract () { debug('opening', this.zipPath, 'with opts', this.opts) - this.zipfile = await (typeof this.zipPath == "string" ? openZip : openBuffer)(this.zipPath, { lazyEntries: true }) + this.zipfile = await (typeof this.zipPath === 'string' ? openZip : openBuffer)(this.zipPath, { lazyEntries: true }) this.canceled = false return new Promise((resolve, reject) => { From f613f07f580f263b67f496f7e7503e05ec96c8d5 Mon Sep 17 00:00:00 2001 From: Leo Nesfield Date: Thu, 20 Aug 2020 19:43:33 +0100 Subject: [PATCH 3/3] Make the linter happy