Available

amalgame-compress

zlib gzip + raw deflate over List<int>.

amc package add compress GitHub ↗ ← Back to the ecosystem

Overview

Thin wrapper around the system zlib: compresses and decompresses List<int> buffers as gzip or raw deflate. You need the zlib headers to install the package (zlib1g-dev on Debian and Ubuntu). Mosaic uses it to compress its HTTP responses.

Features

  • ✓Compress.Gzip / Gunzip: gzip format (RFC 1952), readable by gzip and zcat
  • ✓Compress.Deflate / Inflate: raw deflate (RFC 1951), no header
  • ✓GzipString / GunzipString to go from text to gzip and back
  • ✓Linked to the system zlib (-lz)

Limits

  • –Fixed compression level: zlib's default.
  • –No streaming: the whole buffer is in memory.
  • –On error, the result is an empty list, with no detail.
  • –GunzipString expects text; for binary data, use Gunzip.

Example

After amc package add compress, put this code in main.am and run amc run main.am.

import Amalgame.Collections
import Amalgame.Compress

public class Program {
    public static void Main() {
        let text: string = String_Repeat("repeated string ", 100)   // 1600 bytes

        // gzip (RFC 1952): readable by gzip and zcat
        let gz: List<int> = Compress.GzipString(text)
        Console.WriteLine(String_FromInt(gz.Count()) + " bytes")
        let back: string = Compress.GunzipString(gz)
        if (back == text) {
            Console.WriteLine("round trip ok")
        }

        // raw deflate (RFC 1951), on a byte list
        let raw: List<int> = Compress.Gunzip(gz)
        let d: List<int> = Compress.Deflate(raw)
        let plain: List<int> = Compress.Inflate(d)
        Console.WriteLine(String_FromInt(plain.Count()) + " bytes")   // 1600 bytes
    }
}

At a glance

Related packages