jszip icon indicating copy to clipboard operation
jszip copied to clipboard

Is it allowed to add a file providing a ReadableStream?

Open BlueSialia opened this issue 2 years ago • 2 comments

The function JSZip.file accepts as data an object of the type InputByType. Which can be stream: NodeJS.ReadableStream according to the type definitions. The documentation also states that data can be of the type NodeJS stream.

Now, I am getting the error Can't read the data of '[filename]'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ? when I provide a Readable object.

The error comes from the function prepareContent in the file lib/utils.js because the return value of exports.getTypeOf(data) is undefined. Debugging I've confirmed that data is a Readable but I see that the function exports.getTypeOf has no checks for streams. Just strings, arrays, nodebuffers, uint8arrays and arraybuffers.

I have also noticed that the value exports.nodestream from lib/support.js is not used anywhere.

So, is it an unfinished feature? Or am I doing something wrong?

BlueSialia avatar Feb 23 '23 19:02 BlueSialia

Up

jaxalo avatar Apr 03 '23 08:04 jaxalo

The syntax is like this:

   zip.file(`file-from-readable-stream.txt`, readableStream);

zenstok avatar Feb 01 '24 21:02 zenstok