All Projects → sebastiandev → Zipper

sebastiandev / Zipper

Licence: mit
C++ wrapper around minizip compression library

Programming Languages

cpp
1120 projects

Projects that are alternatives of or similar to Zipper

Datacompression
Swift libcompression wrapper as an extension for the Data type (GZIP, ZLIB, LZFSE, LZMA, LZ4, deflate, RFC-1950, RFC-1951, RFC-1952)
Stars: ✭ 191 (-29.78%)
Mutual labels:  zlib, compression
ZipArchive
A single-class pure VB6 library for zip with ASM speed
Stars: ✭ 38 (-86.03%)
Mutual labels:  compression, zlib
Turbobench
Compression Benchmark
Stars: ✭ 211 (-22.43%)
Mutual labels:  zlib, compression
Zippy
Pure Nim implementation of deflate, zlib, gzip and zip.
Stars: ✭ 88 (-67.65%)
Mutual labels:  zlib, compression
deflate-rs
An implementation of a DEFLATE encoder in rust
Stars: ✭ 47 (-82.72%)
Mutual labels:  compression, zlib
Fast zlib
Heavily optimized zlib compression algorithm
Stars: ✭ 105 (-61.4%)
Mutual labels:  zlib, compression
em inflate
Fast, small, in-memory inflate (zlib, deflate and gzip decompression)
Stars: ✭ 59 (-78.31%)
Mutual labels:  compression, zlib
Fflate
High performance (de)compression in an 8kB package
Stars: ✭ 547 (+101.1%)
Mutual labels:  zlib, compression
zlib
Compression and decompression in the gzip and zlib formats
Stars: ✭ 32 (-88.24%)
Mutual labels:  compression, zlib
power-gzip
POWER9 gzip engine documentation and code samples
Stars: ✭ 16 (-94.12%)
Mutual labels:  compression, zlib
Denoflate
WebAssembly powered Deflate/Gzip/Zlib compression for Deno, written in Rust
Stars: ✭ 80 (-70.59%)
Mutual labels:  zlib, compression
decompress
Pure OCaml implementation of Zlib.
Stars: ✭ 103 (-62.13%)
Mutual labels:  compression, zlib
Zlib Ng
zlib replacement with optimizations for "next generation" systems.
Stars: ✭ 807 (+196.69%)
Mutual labels:  zlib, compression
Uzlib
Radically unbloated DEFLATE/zlib/gzip compression/decompression library. Can decompress any gzip/zlib data, and offers simplified compressor which produces gzip-compatible output, while requiring much less resources (and providing less compression ratio of course).
Stars: ✭ 168 (-38.24%)
Mutual labels:  zlib, compression
Minizip Ng
Fork of the popular zip manipulation library found in the zlib distribution.
Stars: ✭ 750 (+175.74%)
Mutual labels:  zlib, compression
Precomp Cpp
Precomp, C++ version - further compress already compressed files
Stars: ✭ 250 (-8.09%)
Mutual labels:  zlib, compression
Lizard
Lizard (formerly LZ5) is an efficient compressor with very fast decompression. It achieves compression ratio that is comparable to zip/zlib and zstd/brotli (at low and medium compression levels) at decompression speed of 1000 MB/s and faster.
Stars: ✭ 408 (+50%)
Mutual labels:  zlib, compression
Lzbench
lzbench is an in-memory benchmark of open-source LZ77/LZSS/LZMA compressors
Stars: ✭ 490 (+80.15%)
Mutual labels:  zlib, compression
mtscomp
Multichannel time series lossless compression in pure Python based on NumPy and zlib
Stars: ✭ 20 (-92.65%)
Mutual labels:  compression, zlib
zopflipy
A Python bindings for Zopfli
Stars: ✭ 17 (-93.75%)
Mutual labels:  compression, zlib

Zipper

Branch Linux/Mac OS Windows
master Build Status Build status
development Build Status Build status

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.

Features

  • [x] Create zip in memory
  • [x] Allow files, vector and generic streams as input to zip
  • [x] File mappings for replacing strategies (overwrite if exists or use alternative name from mapping)
  • [x] Password protected zip (EAS)
  • [x] Multi platform

Getting Started

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.

Download dependencies

sudo apt-get install zlib1g-dev  # for ubuntu

sudo dnf install zlib-devel  # for fedora
sudo dnf install gcc-c++  # for fedora

Compiling

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

Installing

Following the previous section Compiling, still from the build folder, type:

sudo make install

You will see a message like:

Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libZipper.so.1.0.1
-- Up-to-date: /usr/local/lib/libZipper.so.1
-- Up-to-date: /usr/local/lib/libZipper.so
-- Installing: /usr/local/lib/libZipper.a
-- Installing: /usr/local/lib/libZipper-static.a
-- Installing: /usr/local/bin/Zipper-test
-- Installing: /usr/local/share/pkgconfig/zipper.pc
-- Installing: /usr/local/bin/Zipper-test
-- Installing: /usr/local/include/zipper/crypt.h
-- Installing: /usr/local/include/zipper/ioapi.h
-- Installing: /usr/local/include/zipper/ioapi_buf.h
-- Installing: /usr/local/include/zipper/ioapi_mem.h
-- Installing: /usr/local/include/zipper/iowin32.h
-- Installing: /usr/local/include/zipper/unzip.h
-- Installing: /usr/local/include/zipper/zip.h
-- Installing: /usr/local/include/zipper/CDirEntry.h
-- Installing: /usr/local/include/zipper/defs.h
-- Installing: /usr/local/include/zipper/tools.h
-- Installing: /usr/local/include/zipper/unzipper.h
-- Installing: /usr/local/include/zipper/zipper.h
-- Installing: /usr/local/lib/cmake/zipperConfig.cmake
-- Installing: /usr/local/lib/cmake/zipperTargets.cmake
-- Installing: /usr/local/lib/cmake/zipperTargets-release.cmake

Usage

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 zip file tests and zip memory tests using the awesome BDD's from Catch library )

Zipping

  • Header:
#include <zipper/zipper.h>
using namespace zipper;
  • Creating a zip file with 2 files:
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<unsigned char> zip_vect;
std::ifstream input1("some file");

Zipper zipper(zip_vect);
zipper.add(input1, "Test1");
zipper.close();
  • Adding a password. You can pass your password as a std::string as second parameter to any of constructors:
Zipper zipper("ziptest.zip", "mypassword");
Unzipping
  • Header:
#include <zipper/unzipper.h>
using namespace zipper;
  • 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();
  • Extracting from a vector:
std::vector<unsigned char> zip_vect; // Populated with Zipper zipper(zip_vect);

Unzipper unzipper(zip_vect);
unzipper.extractEntry("Test1")

Note: Methods extract, extractEntry, extractEntryToMemory return a boolean indicating the success (true) or the failure (false).

  • Extraction using a password. You can pass your password as a std::string as second parameter to any of constructors:
Zipper unzipper("ziptest.zip", "mypassword");
Linking Zipper to your project

In your project add the needed headers in your c++ files:

#include <zipper/unzipper.h>
#include <zipper/zipper.h>

There are several ways to link your project against Zipper:

  • Straight forward: g++ -W -Wall -I/usr/local/include main.cpp -o prog -L/usr/local/lib/ -lZipper -lz. Note: you may have to adapt /usr/local to your installation directory (see the previous section Installing). You can also adapt and export your environment variable LD_LIBRARY_PATH (via you .bashrc for example).

  • Pkg-config is a better alternative to the previous command:

g++ -W -Wall main.cpp -o prog `pkg-config zipper --cflags --libs`

Indeed pkg-config knows for you where to find libraries and, by default, it will choose the shared library. In the case it is not present then the static library will be chosen. You can force choosing the static library with pkg-config libZipper --static --libs

  • Makefile: set LDFLAGS to pkg-config zipper --libs and set CPPFLAGS to pkg-config zipper --cflags

  • CMake: Simply place zipper in your project hieracy, and then use add_subdirectory(zipper) or whatever you called the zipper folder. Then link it with Zipper/staticZipper

Project(projZipper)

add_subdirectory(zipper)

add_executable(projZipper main.cpp)
target_link_libraries(
    projZipper
    PUBLIC
    staticZipper
)
Coding style

Before submitting a pull request, you can ident the code with the following command:

cd src
clang-format -i *.cpp *.h
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].