badSantos
badSantos

Reputation: 1029

Zipping a file from memory in linux

I'm working 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!

Upvotes: 2

Views: 2119

Answers (3)

Aaron Digulla
Aaron Digulla

Reputation: 328830

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.

Upvotes: 1

Georg Fritzsche
Georg Fritzsche

Reputation: 99112

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).

Upvotes: 1

Cédric Julien
Cédric Julien

Reputation: 80851

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.

Upvotes: 3

Related Questions