Streams and Decompression error: "unexpected end of file"
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.
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!
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.
Closing after no activity on this issue for 12 months.