C++ wrapper around minizip compression library
Zipper's goal is to bring the power and simplicity of minizip to a more object oriented/c++ user friendly library. It was born out of the necessity of a compression library that would be reliable, simple and flexible. By flexibility I mean supporting all kinds of inputs and outputs, but specifically been able to compress into memory instead of been restricted to file compression only, and using data from memory instead of just files as well.
- Create zip in memory
- Allow files, vector and generic streams as input to zip
- File mappings for replacing strategies (overwrite if exists or use alternative name from mapping)
- Password protected zip
- Multi platform
In order to use and compile zipper you need to have zlib source files. Zipper depends on minizip as well but since it is used as a submodule, you get it when cloning the repo and it gets compiled with the project.
Note: For windows users, zlib is expected to be found at ZLIBROOT.
sudo apt-get install zlib-dev # for ubuntu
sudo dnf install zlib-devel # for fedora
sudo dnf install gcc-c++ # for fedora
The preferred way is to create a folder for the compilation output to avoid polluting the root folder
git clone --recursive https://github.com/sebastiandev/zipper.git # to get zipper and minizip submodule
cd zipper
mkdir build
cd build
cmake ../
make
There are two classes available Zipper and Unzipper. They behave in the same manner regarding constructors and storage parameters. (for a complete example take a look at the tests using the awesome BDD's from Catch library )
- Creating a zip file with 2 files:
using namespace zipper;
std::ifstream input1("some file");
std::ifstream input2("some file");
Zipper zipper("ziptest.zip");
zipper.add(input1, "Test1");
zipper.add(input2, "Test1");
zipper.close();
- Adding a file by name and an entire folder to a zip:
Zipper zipper("ziptest.zip");
zipper.add("somefile.txt");
zipper.add("myFolder");
zipper.close();
- Creating a zip file using the awesome streams from boost that lets us use a vector as a stream:
#include <boost\interprocess\streams\vectorstream.hpp>
...
boost::interprocess::basic_vectorstream<std::vector<char>> input_data(some_vector);
Zipper zipper("ziptest.zip");
zipper.add(input_data, "Test1");
zipper.close();
- Creating a zip in memory stream with files:
#include <boost\interprocess\streams\vectorstream.hpp>
...
boost::interprocess::basic_vectorstream<std::vector<char>> zip_in_memory;
std::ifstream input1("some file");
Zipper zipper(zip_in_memory);
zipper.add(input1, "Test1");
zipper.close();
- Creating a zip in a vector with files:
std::vector<char> zip_vect;
std::ifstream input1("some file");
Zipper zipper(zip_vect);
zipper.add(input1, "Test1");
zipper.close();
- Getting all entries in zip
Unzipper unzipper("zipfile.zip");
std::vector<ZipEntry> entries = unzipper.entries();
unzipper.close();
- Extracting all entries from zip
Unzipper unzipper("zipfile.zip");
unzipper.extract();
unzipper.close();
- Extracting all entries from zip using alternative names for existing files on disk
std::map<std::string, std::string> alternativeNames = { {"Test1", "alternative_name_test1"} };
Unzipper unzipper("zipfile.zip");
unzipper.extract(".", alternativeNames);
unzipper.close();
- Extracting a single entry from zip
Unzipper unzipper("zipfile.zip");
unzipper.extractEntry("entry name");
unzipper.close();
- Extracting a single entry from zip to memory
std::vector<unsigned char> unzipped_entry;
Unzipper unzipper("zipfile.zip");
unzipper.extractEntryToMemory("entry name", unzipped_entry);
unzipper.close();
zipper's People
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.