text_fonts

module std::deflatesource

Deflate (RFC 1951) and gzip (RFC 1952): inflating what a server or a PNG compressed, its Huffman codes looked up nine bits at a time, and compressing what a program writes about as zlib's best level does (repeats found through chains of hashes and looked for again a byte on, blocks of their own Huffman codes).

import std::vector;
import std::result;

const text = "a line, a line, a line, a line";
const packed = gzip(&text);
expect(packed.length() < text.length() + 18);
if (gunzip(&packed.view(), 1000) is ::Ok |&back|) {
    expect(back.view() == text);
} else {
    expect(false);
}
expect(gunzip(&packed.view(), 10) == Result<Vector<u8>, InflateError>::Err(InflateError::TooLarge));

type InflateErrorsource

exp type InflateError = enum

Why inflating stopped.

Variants

Damaged

the data is not a whole stream

TooLarge

it inflates past the limit given

fn inflatesource

exp fn inflate(data: &[u8], out: &var Vector<u8>, limit: u64) -> Result<u64, InflateError>

Inflates the deflate stream into out, whose bytes it writes from the start, growing it past its length when it must, up to limit bytes: how many it wrote.

fn gunzipsource

exp fn gunzip(data: &[u8], limit: u64) -> Result<Vector<u8>, InflateError>

The data of the gzip members, one after another (RFC 1952, 2.2), inflated up to limit bytes in all, each member's length and CRC-32 checked.

fn gzipsource

exp fn gzip(data: &[u8]) -> Vector<u8>

The data compressed as a gzip member, with no name nor time.

fn deflatesource

exp fn deflate(data: &[u8]) -> Vector<u8>

The data compressed: each repeat of three bytes or more the longest among the last 64 places of the same hash in the window, kept only when the byte after it starts no longer one (zlib's lazy matching), in blocks of 16384 literals and repeats, each written with its own Huffman codes, the fixed codes or stored, whichever is shortest.

import std::vector;
import std::result;

var text = Vector<u8>::empty();
for ([..200 to u64]) {
    text.append(&"a line again, ");
}
const packed = deflate(&text.view());
expect(packed.length() < 100);
var back = Vector<u8>::empty();
const length = Result<u64, InflateError>::Ok(text.length());
expect(inflate(&packed.view(), &var back, text.length()) == length);
expect(back.view() == text.view());

fn crc32source

exp fn crc32(data: &[u8]) -> u32

The CRC-32 of gzip, PNG and zip (the reflected polynomial 0xEDB88320).