Comments (6)
It will require many small changes in minizip
, so if your files are not super big you can read them into memory and use zip_stream_...
API
from zip.
from zip.
Yeah, definitivelly ( it does not sound like a big archive). You can do sth. like:
https://github.com/kuba--/zip/blob/master/test/test_entry.c#L176
from zip.
from zip.
I assume you already have a file descriptor where you want to save the zip stream.
Then:
// create zip stream in memory
struct zip_t *zip = zip_stream_open(NULL, 0, ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
// write some data
zip_entry_open(zip, "entry1.txt");
const char *txt = "This is content for entry1.txt\0";
zip_entry_write(zip, txt, strlen(txt));
zip_entry_close(zip);
// get zip stream into the buffer
void *buf = NULL;
size_t bufsize = 0;
zip_stream_copy(zip, (void **)&buf, &bufsize);
zip_stream_close(zip);
// we should already have a file descriptor
int fd = open("/tmp/file.zip", O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR | S_IWUSR);
// write zip stream to your file descriptor
write(fd, buf, bufsize);
close(fd);
// remember to free memory allocated for the buffer!
free(buf);
$ zipinfo /tmp/file.zip
Archive: /tmp/file.zip
Zip file size: 179 bytes, number of entries: 1
-rw---- 0.0 fat 30 bX defN 23-Mar-19 13:36 entry1.txt
1 file, 30 bytes uncompressed, 29 bytes compressed: 3.3%
$ unzip /tmp/file.zip
$ cat entry1.txt
This is content for entry1.txt%
Keep in mind - there is no error checking in above example.
Good luck!
from zip.
from zip.
Related Issues (20)
- Failed to build using mingw 11 x64 (duplicate) HOT 3
- Compressing large files that exceed 4GB will fail HOT 1
- Update files in zip HOT 1
- Failed to compress files with Chinese names in Windows system HOT 1
- Extract without a path HOT 2
- How to change to zip and not use zip64? HOT 3
- Open a .zip file with a password. HOT 1
- Segmentation fault on entry deletion HOT 1
- How to split a file in different chunked files? HOT 2
- SonarQube security hotspot HOT 4
- m_pPut_buf_func always null HOT 1
- Bug when delete a file from a big size zip archive HOT 3
- Warnings HOT 1
- zip_create Why does create not support directory creation! HOT 3
- zip_extract The extracted file name is garbled and does not support Chinese name extraction HOT 1
- typedef conflict HOT 1
- zip_close error when opening zip archive in read mode HOT 5
- Check if file or stream is a valid "zip" archive HOT 10
- 64-bit Linux compatibility HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zip.