Skip to content

compression.aug ​

Compression with zlib · Source and specification

Files in this project

Code ​

aug
// aug-spec: "compression.aug.md" explains this file. Read it before changes; refresh with aug spec.
import CompressionError and compress and decompress from "https://github.com/GreenPandaStudios/aug-zlib#fce52e3bf536a304fab82d1d4b95ae425c027be1"
/** Compress text with zlib, then restore its bytes within a fixed output limit. */
roundTrip() returns Bytes unless CompressionError:
    Bytes input = "The world runs on language".bytes()
    Bytes compressed = compress(input)
    return decompress(input=compressed, maximumOutput=4096)
test roundTrip:
    when "compression":
        it "preserves_the_original_bytes":
            Bytes restored = roundTrip()
            assert(restored.text() == "The world runs on language")
            assert(restored.length() == 26)
aug
// aug-spec: "compression.aug.md" explains this file. Read it before changes; refresh with aug spec.
import CompressionError and compress and decompress from "https://github.com/GreenPandaStudios/aug-zlib#fce52e3bf536a304fab82d1d4b95ae425c027be1"
/** Compress text with zlib, then restore its bytes within a fixed output limit. */
roundTrip() returns Bytes unless CompressionError {
    Bytes input = "The world runs on language".bytes()
    Bytes compressed = compress(input)
    return decompress(input=compressed, maximumOutput=4096)
}
test roundTrip {
    when "compression" {
        it "preserves_the_original_bytes" {
            Bytes restored = roundTrip()
            assert(restored.text() == "The world runs on language")
            assert(restored.length() == 26)
        }
    }
}

Compiled specification ​

Interactions and sequences

roundTrip · source ​

Compress text with zlib, then restore its bytes within a fixed output limit. Failures can raise CompressionError.

It sets input of type Bytes to the UTF-8 bytes of "The world runs on language". It sets compressed of type Bytes to compress with input. It returns decompress with input from compressed and maximumOutput 4096. source

Checked interface
text
roundTrip() returns Bytes unless CompressionError

Failures can raise CompressionError.

test roundTrip · source ​

Tests roundTrip. Each case gets fresh setup and dependencies.

compression ​

preserves_the_original_bytes · source ​

It gets restored of type Bytes from roundTrip. The test requires restored.text equals "The world runs on language". The test requires the byte length of restored equals 26. source

Dependencies ​

It uses compress, decompress, and CompressionError from https://github.com/GreenPandaStudios/aug-zlib#fce52e3bf536a304fab82d1d4b95ae425c027be1.

Built-in operations follow the language reference.

Last updated:

The world runs on language