Filter löschen
Filter löschen

Save a stream of bytes into a zip file

2 Ansichten (letzte 30 Tage)
Naum Derzhi
Naum Derzhi am 24 Okt. 2022
Kommentiert: Naum Derzhi am 25 Okt. 2022
I need to save a large array, which I have in memory, compressing it while saving.
I can, of course, write the stream of bytes (e.g., use fopen->fwrite->fclose) into a temporary file and then zip this file (zip zipname.zip tempfilename). Bu this is inefficient. What I would like to do is to create a zip archive on disk without an intermediate file. For example, zip memory to memory, i.e. create the zip structure in memory (where the contents is my compressed array, and the file name is somehing I will provide), and then write this structure as a stream of bytes to <zipname.zip>.
Is this possible?
Any ideas will be deeply appreciated.
Thank you in advance

Akzeptierte Antwort

dpb
dpb am 24 Okt. 2022
PKZip was/is shareware, it should be possible to turn the code for it into a callable mex file that works from memory; it's quite possible somebody else has already done this but I didn't find it in a (very) quick search. But, <https://www.hanshq.net/zip.html> is a link that has a C implementation as starting point.
Something fast and ready-built is to just use the temporary file and call the packaged zip interface in MATLAB.
  2 Kommentare
Naum Derzhi
Naum Derzhi am 24 Okt. 2022
Thank you very much.
Just to confirm: no off-the-shelf Matlab function provides this functionality, right?
dpb
dpb am 24 Okt. 2022
Not from memory, no.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 24 Okt. 2022
Bearbeitet: Walter Roberson am 24 Okt. 2022
It is possible by calling on Java.
I do not have appropriate code at the moment, but you can get an indication of the kinds of functions you need by looking at https://www.mathworks.com/matlabcentral/answers/523965-read-mat-files-inside-a-zip-file-without-extracting-unzipping-the-zip-file#answer_431173

Kategorien

Mehr zu Files and Folders finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by