开发者

Zipping a file from memory in linux

I'm worki开发者_JAVA技巧ng on application that must enrypt and zip files. So, I create some data in memory (text, binary or whatever), encrypt it and save to disk (file1 and file2). The I call e.g. "zip out.zip file1 file2 ".

I do not want to save this files to disk, but immediately create zip and pack these files from memory.

How should I do that?

Thanks a lot!


You could try to use the zlib library to be able to create zip files from memory buffers.

The boost:iostreams could also be a good solution.


For zlib there is an extension for zip called minizip in the contribs. For minizip you can find code to work with in-memory buffers on the authors page:

Justin Fletcher wrote a very simple implementation of a memory access method for the ioapi code (ioapi_mem_c.zip).


Note that you must compress first and then encrypt. Encrypted data can't be compressed anymore.

Interestingly enough, I wasn't able to find a library to create ZIP files from C. zlib only allows to (de-)compress individual entries in a ZIP archive.

It comes with contrib/minizip; maybe that can get you started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜