Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream finished in an invalid state, uncompression failed #14

Open
kilsen opened this issue Feb 4, 2018 · 9 comments
Open

Stream finished in an invalid state, uncompression failed #14

kilsen opened this issue Feb 4, 2018 · 9 comments

Comments

@kilsen
Copy link

kilsen commented Feb 4, 2018

I'm getting the error "Stream finished in an invalid state, uncompression failed" on some ZIP files. Do you know what might be the cause? When it happens, is there a proper way to shut down the stream so that it no longer produces entries?

@mhr3
Copy link
Owner

mhr3 commented Feb 4, 2018

Difficult to say without the zip file itself, might be a fixable bug, might be that the zip file was produced in a way that makes it impossible to process by streaming.

From README:

Please note that the zip file format isn't really meant to be processed by streaming, though this library should succeed in most cases, if you do have complete zip file available, you should consider using other libraries which read zip files from the end - as originally intended (for example yauzl or decompress-zip).

@kilsen
Copy link
Author

kilsen commented Feb 4, 2018 via email

@mhr3
Copy link
Owner

mhr3 commented Feb 4, 2018

If you have control over the original zip file you can just try to compress it with a different program - for example the Mac archive utility should produce zips that can be always processed with a streaming unzip.

@kilsen
Copy link
Author

kilsen commented Feb 4, 2018 via email

@mhr3
Copy link
Owner

mhr3 commented Feb 4, 2018

Fair enough, if you have an example zip that can be shared, I can have a look if it's something fixable.

@qburst-akhil
Copy link

Hi,
I got this same issue, if I downlaod the zip file and uncompress it locally its works without any problem.
But if I try to stream the file over network and uncompress it using pipe it throws this error.

var readStream = sftp.createReadStream(/Import/${fileNameArray[0]}); readStream.pipe(unzip.Parse()) .pipe(stream.Transform({ objectMode: true, transform: (entry, encoding, callback) => { console.log(Inside transform callback....); const outputPath = path.join(dir, entry.path); entry.pipe(fs.createWriteStream(outputPath)) .on('finish', () => { console.log(Done writing file ${entry.path}); }) .on('error', err => { console.log(Error writing stream ${JSON.stringify(err)}); }); } }));

Erro thrown is as shown below:

Error: Stream finished in an invalid state, uncompression failed
at UnzipStream._flush (/home/user/Nodejs/fileDownload/node_modules/unzip-stream/lib/unzip-stream.js:734:19)
at UnzipStream.prefinish (_stream_transform.js:137:10)
at emitNone (events.js:106:13)
at UnzipStream.emit (events.js:208:7)
at prefinish (_stream_writable.js:603:14)
at finishMaybe (_stream_writable.js:611:5)
at endWritable (_stream_writable.js:622:3)
at UnzipStream.Writable.end (_stream_writable.js:573:5)
at ParserStream._flush (/home/user/Nodejs/fileDownload/node_modules/unzip-stream/lib/parser-stream.js:33:22)
at ParserStream.prefinish (_stream_transform.js:137:10)

@mhr3
Copy link
Owner

mhr3 commented Jul 10, 2018

@pomelio
Copy link

pomelio commented Dec 30, 2018

I got same error.

Before unzip, I print out the file size. The file size is correct.
when the program second time unzip the file. It runs successfully.

(node:25) UnhandledPromiseRejectionWarning: Error: Stream finished in an invalid state, uncompression failed
appstore-api-server_1_450bccf02a4c | at UnzipStream._flush (/node_modules/unzip-stream/lib/unzip-stream.js:734:19)
appstore-api-server_1_450bccf02a4c | at UnzipStream.prefinish (_stream_transform.js:137:10)
appstore-api-server_1_450bccf02a4c | at emitNone (events.js:106:13)
appstore-api-server_1_450bccf02a4c | at UnzipStream.emit (events.js:208:7)
appstore-api-server_1_450bccf02a4c | at prefinish (_stream_writable.js:602:14)
appstore-api-server_1_450bccf02a4c | at finishMaybe (_stream_writable.js:610:5)
appstore-api-server_1_450bccf02a4c | at endWritable (_stream_writable.js:621:3)
appstore-api-server_1_450bccf02a4c | at UnzipStream.Writable.end (_stream_writable.js:572:5)
appstore-api-server_1_450bccf02a4c | at Extract._flush (/node_modules/unzip-stream/lib/extract.js:41:22)
appstore-api-server_1_450bccf02a4c | at Extract.prefinish (_stream_transform.js:137:10)

@drmrbrewer
Copy link

Getting the same error occasionally:

Error: Stream finished in an invalid state, uncompression failed
	at UnzipStream._flush (/usr/src/app/node_modules/unzip-stream/lib/unzip-stream.js:734:19)
	at UnzipStream.prefinish (_stream_transform.js:142:10)
	at UnzipStream.emit (events.js:314:20)
	at prefinish (_stream_writable.js:628:14)
	at finishMaybe (_stream_writable.js:636:5)
	at endWritable (_stream_writable.js:656:3)
	at UnzipStream.Writable.end (_stream_writable.js:595:5)
	at ParserStream._flush (/usr/src/app/node_modules/unzip-stream/lib/parser-stream.js:33:22)
	at ParserStream.prefinish (_stream_transform.js:142:10)
	at ParserStream.emit (events.js:314:20)

For some context, I am piping a read stream into unzip-stream from a remote file (fetched using gaxios using responseType: 'stream'). Mostly this works fine. When it doesn't work (with the above error) it is always when the node on which this is running is also fetching and processing lots of other files (in other node apps running on the same node)... so resources are somewhat limited. My guess is that the remote fetch operation times out after some time, so that the stream into unzip-stream ends prematurely. Is there any way to avoid this?

Incidentally, I get an equivalent error under the same circumstances with related node-unzipper... see here... I came to this library in the hope that it performed better in these circumstances but it looks like it fails in a similar way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants