hzeller / ziplain

A plain, no-frills ZIP file writer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZIPlain

A plain, no-frills ZIP-file encoder with a simple API.

Provides class ziplain::Encoder to create a ZIP file. Abstractions for ByteSource and ByteSink allow to adapt it to local IO requirements.

Build

There is a simple Makefile included for a standard build and test.

make test

(TODO: create a make install with pkg-config).

Also, for integration in bazel-based builds, a MODULE.bazel and BUILD is included.

bazel build :ziplain

Example use

In the following example, we provide the output ByteSink by implementing a closure wrapping a FILE* stream. As input ByteSource, ziplain-provided wrappers for files and in-memory representations are used.

See demo.cc for full example.

constexpr int kCompressionLevel = 9;
FILE *out = fopen("test-output.zip", "wb");
ziplain::Encoder zipper(kCompressionLevel, [out](std::string_view s) {
  return fwrite(s.data(), 1, s.size(), out) == s.size();
});

zipper.AddFile("ziplain.h", ziplain::FileByteSource("ziplain.h"));
zipper.AddFile("ziplain.cc", ziplain::FileByteSource("ziplain.cc"));
zipper.AddFile("readme.txt", ziplain::MemoryByteSource("Hello world!\n"));
zipper.Finish();

fclose(out);

About

A plain, no-frills ZIP file writer.

License:Apache License 2.0


Languages

Language:C++ 90.0%Language:Starlark 4.7%Language:Nix 2.9%Language:Shell 1.2%Language:Makefile 1.2%