Save a stream of bytes into a zip file
Show older comments
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
Accepted Answer
More Answers (1)
Walter Roberson
on 24 Oct 2022
Edited: Walter Roberson
on 24 Oct 2022
0 votes
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
See also https://www.mathworks.com/matlabcentral/answers/11910-how-do-i-specify-the-compression-level-to-gzip#answer_16299 which shows working with zip output files.
1 Comment
Naum Derzhi
on 25 Oct 2022
Categories
Find more on Database Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!