If anyone is interested in learning gzip/deflate

100 points techhara

Hi Rustaceans,

https://github.com/techhara/gunzip/

I wrote yet another gzip library for decompressing .gz file from scratch in safe Rust for my own educational purposes. It is only \~1000 lines of code mostly vanilla implementation, but also has some advanced features, such as multithread support and streaming API.

I have organized the branches in incremental step to make it really easy to follow along

  • branch 1: main() function and skeletal structure
  • branch 2: bitread module for reading bits from a byte stream
  • branch 3: gzip header & footer for parsing the metadata and checksum
  • branch 4: inflate for block type 0 (uncompressed) data
  • branch 5: codebook and huffman\_decoder modules for decoding Huffman codes
  • branch 6: lz77 and sliding\_window modules for decompressing LZ77-encoded data
  • branch 7: inflate for block type 1 and 2 (compressed) data using fixed or dynamic Huffman codes
  • branch 8: checksum\_write module for verifying the decompressed data
  • branch 9: performance optimization
  • branch 10: multithread support
  • branch 11: streaming support

Though the library focuses on simplicity, it still runs faster than miniz\_oxide rust backend flate2-rs on x64 and comparable on arm64 systems. I didn't do extensive testing, so it is not production-ready, but if anyone is interested in learning gzip/deflate or want to write it from scratch, feel free to check it out.

https://preview.redd.it/46cc0fm2nyub1.png?width=605&format=png&auto=webp&s=765e656c4c9789185f4a99463eaf660b8834d69e

https://preview.redd.it/m8yx4zz3nyub1.png?width=605&format=png&auto=webp&s=2223fd417d5c69e5689fd43f5a00bb776ddb87c9