hdorio/hwzip.zig
Zig version of hwzip
It's a port in Zig of the program hwzip-2.1 written by Hans Wennborg.
hwzip is an example implementation written in C of the Zip file format.
hwzip.zig is a Zig version in an attempt to make it more accessible.
I tried to make the least amount of changes possible so that one can still follow the article with the Zig code instead of C. This means it's not idiomatic Zig code, it's more a translation than a port.
Because you can compile, test and run it without any dependencies (except Zig). The C version requires the usual hell of building utilities, the Info-ZIP binary, and links into zlib.
I needed a way to compress files in Zig.
I wanted to learn about Zip files and Zig is much more readable to me than C.
Download and install Zig 0.9.1
To build the binary in ./zig-out/bin/hwzip
you need to run
zig build
zig build test
Executing without any arguments print the help message
./hwzip list <zipfile>
./hwzip extract <zipfile>
./hwzip create <zipfile> [-m <method>] [-c <comment>] <files...>
Supported compression methods:
store, shrink, reduce, implode, deflate (default).
huffman_decoder_t.num_syms
is commented out.std.hash.crc32()
from Zig instead of a custom one.zip.ctime2dos()
reverse8_tbl
is replaced by the function bits.reverse8()
.hwzip.zig comes with no warranties, I may have introduced bugs which are not in the original version hwzip-2.1.
You cannot recursively compress files within a directory, you need to list all files that you want to add to the archive.
This utility is slow and is not meant for daily use, you should use more serious tools like Info-ZIP, 7zip or gzip to compress your files.
The ./doc
directory contains a copy of the articles explaining the Zip file format which are under Hans Wennborg copyright.
time.zig
is a port of some portion of src/time
from musl libc and as such this file is under the standard MIT license, see the LICENSE-time-dot-zig
file.
The rest is public domain unless specified otherwise, see the LICENSE
file.