Closed Allypost closed 3 years ago
Hi! I think it's because you're not waiting for streams to finish:
await zip.stream(entry) // waits for the stream to become available
.then((stream) => // the stream is ready now
stream.end() // does nothing: ReadableStream is closed when `end` event is emitted
);
Just tried your example, it works if you change it like this:
for (const entry of Object.values(await zip.entries())) {
const stream = await zip.stream(entry);
await new Promise((resolve) => stream.on('end', resolve));
}
When at least one entity in a zip file is converted to a stream, the library throws a bad file descriptor error:
This is the code that I tested:
It works if the
await zip.close()
line is omitted. It also works fine if the entity is not converted to a stream (thezip.stream
method isn't used).The files I tested with were generated by zipping 1MB of random bytes:
This was tested/observed on Manjaro Linux and inside an Alpine docker image.
I only saw an example for streaming one file but the description for the
.close
method implies multiple streams can be opened. I may be wrong in that assumption but then a disclaimer should be put in place to warn of incorrect usages.