help icon indicating copy to clipboard operation
help copied to clipboard

Streams and Decompression error: "unexpected end of file"

Open prettydiff opened this issue 3 years ago • 2 comments

Details

I am streaming a file from a server using this logic:

const hash = createHash("sha3-512"),
    readStream = createReadStream(data.path_source),
    compress = createBrotliCompress({
        params: {[constants.BROTLI_PARAM_QUALITY]: data.brotli}
    });
readStream.pipe(compress).pipe(socket);

On the client I am attempting to write the file like this:

const hash = createHash("sha3-512"),
    writeStream = createWriteStream(writePath),
    decompress = createBrotliDecompress();
socket.pipe(decompress).pipe(writeStream);

I have tried various different files on both Windows and Ubuntu and I continue to get error Z_BUF_ERROR "unexpected end of file". Am I piping incorrectly?

Node.js version

17.1.0, 18.2.0

Example code

17.1.0, 18.2.0

Operating system

Windows and Ubuntu

Scope

Runtime.

Module and version

Not applicable.

prettydiff avatar May 27 '22 14:05 prettydiff

While I haven't experienced this issue myself, you might consider using stream's pipeline function when piping multiple streams together. My guess is that your input streams are ending but not notifying the compression stream. You could also look at the Brotli options for flush/flush_finish. And for these kind of stream errors I usually try adding event listeners for end, close, finish, error etc. events to all my streams or use NODE_DEBUG="streams*" to trace/console.log any closure events before/after the error.

Good luck!

lselden avatar May 31 '22 13:05 lselden

There has been no activity on this issue for 11 months. The help repository works best when sustained engagement moves conversation forward. The issue will be closed in 1 month. If you are still experiencing this issue on the latest supported versions of Node.js, please leave a comment.

github-actions[bot] avatar Mar 05 '24 01:03 github-actions[bot]

Closing after no activity on this issue for 12 months.

github-actions[bot] avatar Apr 04 '24 01:04 github-actions[bot]