From cb24d9cf32765f5bb6537c1d7aa32b5f58d1cadd Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 9 Mar 2024 17:47:44 -0600 Subject: [PATCH 1/4] expand stream test --- test/zip-archive-output-stream.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/zip-archive-output-stream.js b/test/zip-archive-output-stream.js index ba2bbf7b..7f47e39d 100644 --- a/test/zip-archive-output-stream.js +++ b/test/zip-archive-output-stream.js @@ -3,6 +3,7 @@ var fs = require('fs'); var stream = require('stream'); var assert = require('chai').assert; var mkdir = require('mkdirp'); +var Readable = require('readable-stream').Readable; var helpers = require('./helpers'); var WriteHashStream = helpers.WriteHashStream; @@ -48,6 +49,20 @@ describe('ZipArchiveOutputStream', function() { archive.entry(entry, fs.createReadStream('test/fixtures/test.txt')).finish(); }); + it('should append Stream-like sources', function(done) { + var archive = new ZipArchiveOutputStream(); + var testStream = new WriteHashStream('tmp/zip-stream-like.zip'); + var entry = new ZipArchiveEntry('stream-like.txt'); + + testStream.on('close', function() { + done(); + }); + + archive.pipe(testStream); + + archive.entry(entry, new Readable()).finish(); + }); + it('should stop streaming on Stream error', function(done) { var archive = new ZipArchiveOutputStream(); var testStream = new WriteHashStream('tmp/zip-stream.zip'); @@ -129,4 +144,4 @@ describe('ZipArchiveOutputStream', function() { }); }); -}); \ No newline at end of file +}); From c9a1ef729f1c563314babe461f36e2b5c894b9dd Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 9 Mar 2024 18:00:55 -0600 Subject: [PATCH 2/4] add is-stream@^2.0.0 --- package-lock.json | 21 +++++++++++++++++++-- package.json | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 15943e33..eb20bcf0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,17 @@ { "name": "compress-commons", - "version": "6.0.0", + "version": "6.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "compress-commons", - "version": "6.0.0", + "version": "6.0.1", "license": "MIT", "dependencies": { "crc-32": "^1.2.0", "crc32-stream": "^6.0.0", + "is-stream": "^2.0.1", "normalize-path": "^3.0.0", "readable-stream": "^4.0.0" }, @@ -777,6 +778,17 @@ "node": ">=8" } }, + "node_modules/is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-unicode-supported": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", @@ -2122,6 +2134,11 @@ "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", "dev": true }, + "is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==" + }, "is-unicode-supported": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", diff --git a/package.json b/package.json index 867778b9..20cb5525 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "dependencies": { "crc-32": "^1.2.0", "crc32-stream": "^6.0.0", + "is-stream": "^2.0.1", "normalize-path": "^3.0.0", "readable-stream": "^4.0.0" }, From ce7406626ab7367578a7a06207796a29bac01939 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 9 Mar 2024 18:09:16 -0600 Subject: [PATCH 3/4] use isStream --- lib/archivers/archive-output-stream.js | 3 ++- lib/util/index.js | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/archivers/archive-output-stream.js b/lib/archivers/archive-output-stream.js index b5fa4939..d349b5e6 100644 --- a/lib/archivers/archive-output-stream.js +++ b/lib/archivers/archive-output-stream.js @@ -6,6 +6,7 @@ * https://github.com/archiverjs/node-compress-commons/blob/master/LICENSE-MIT */ var inherits = require('util').inherits; +var isStream = require('is-stream'); var Transform = require('readable-stream').Transform; var ArchiveEntry = require('./archive-entry'); @@ -84,7 +85,7 @@ ArchiveOutputStream.prototype.entry = function(ae, source, callback) { if (Buffer.isBuffer(source)) { this._appendBuffer(ae, source, callback); - } else if (util.isStream(source)) { + } else if (isStream(source)) { this._appendStream(ae, source, callback); } else { this._archive.processing = false; diff --git a/lib/util/index.js b/lib/util/index.js index 20a67833..0fcc60f9 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -7,19 +7,16 @@ */ var Stream = require('stream').Stream; var PassThrough = require('readable-stream').PassThrough; +var isStream = require('is-stream'); var util = module.exports = {}; -util.isStream = function(source) { - return source instanceof Stream; -}; - util.normalizeInputSource = function(source) { if (source === null) { return Buffer.alloc(0); } else if (typeof source === 'string') { return Buffer.from(source); - } else if (util.isStream(source) && !source._readableState) { + } else if (isStream(source) && !source._readableState) { var normalized = new PassThrough(); source.pipe(normalized); From bb31348059c93f0574d18827d14375449b0a1f92 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 9 Mar 2024 18:36:56 -0600 Subject: [PATCH 4/4] rework test --- test/zip-archive-output-stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/zip-archive-output-stream.js b/test/zip-archive-output-stream.js index 7f47e39d..1c1ca8c1 100644 --- a/test/zip-archive-output-stream.js +++ b/test/zip-archive-output-stream.js @@ -60,7 +60,7 @@ describe('ZipArchiveOutputStream', function() { archive.pipe(testStream); - archive.entry(entry, new Readable()).finish(); + archive.entry(entry, Readable.from(['test'])).finish(); }); it('should stop streaming on Stream error', function(done) {