Compress/decompress from and to memory rather than file #435
-
Can zip.js be used to compress/decompress from and to a variable (string I guess) rather than a file? I'd like to be able to send a compressed buffer to a server, as well as decompress that buffer when received. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
You should not use a string to store binary data. Depending on the size of the data, you can use an instance of |
Beta Was this translation helpful? Give feedback.
-
I want to compress/decompress data and also gain encryption, but I want to read/write files using my existing routines - since in Capacitor (mobile app) I can't use anything but their native read/write routines. So I want to encrypt/compress JSON data into a buffer and write that buffer out/read it back in myself. So I hoped I could use some functionality of zip.js and gain encryption. (So far I've used pako, which works well but doesn't support encryption.) Thanks! |
Beta Was this translation helpful? Give feedback.
-
Got it - and I put together some test code in both my environments - Electron and Capacitor - and looks like this is going to work well. Thanks again for the help!! |
Beta Was this translation helpful? Give feedback.
You should not use a string to store binary data. Depending on the size of the data, you can use an instance of
ReadableStream
(see https://github.com/gildas-lormeau/zip.js/blob/master/tests/all/test-readable-stream.js), orBlobReader
(see https://github.com/gildas-lormeau/zip.js/blob/a64c5238c6bd20b64b6aa32551e80347289ac5fb/tests/all/test-blob.js), orUint8ArrayReader
(see https://github.com/gildas-lormeau/zip.js/blob/master/tests/all/test-array.js).