Skip to content
FutureBlitz

    Install

    Import std.compress.zstd

    std.compress.zstd

    Zstandard compression.

    Zstd (RFC 8878), over zstd. Its Compress and Decompress work at once, and its Compressor and Decompressor take bytes in turn and give what came out of them so far, for data that comes in parts. Levels go from 1, the fastest, to 22, the smallest, and are 3 by default, as zstd's; those past 19 take much more memory. Each frame has its content's checksum, and a Compress's says its size. A Decompress reads frames one after another, as zstd does, skipping skippable ones.

    Examples

    // Each format's Compressor and Decompressor take bytes in turn.
    Local compressor = ZstdCompressor(3)
    Local packed = compressor.Add("a part, and ".Bytes)
    packed.AddAll(compressor.Add("the rest".Bytes))
    packed.AddAll(compressor.Finish())
    Local decompressor = ZstdDecompressor()
    Local text = Try decompressor.Add(packed)
    text.AddAll(Try decompressor.Finish())
    Expect(String.FromUtf8(text) == "a part, and the rest")

    std/compress/zstd.fb

    Types

    Zstd struct

    Public Struct Zstd

    Zstd's frames, of .zst files.

    Examples

    Local data = "again and again and again and again".Repeated(100).Bytes
    Local packed = Zstd.Compress(data, 19)
    Expect(packed.Count < data.Count)
    Local unpacked = Try Zstd.Decompress(packed)
    Expect(unpacked == data)

    std/compress/zstd.fb, line 53

    • @PanicsAtCaller Public Static Method Compress(data: UInt8[], level: Int = 3): UInt8[] static method #

      The data, compressed at the level. Panics when the level isn't from 1 to 22.

    • @PanicsAtCaller Public Static Method Decompress(data: UInt8[], limit: Int = MOST_BYTES): UInt8[] Throws IOError static method #

      The bytes the data is compressed from, each frame's after the last's, or an IOError when it isn't Zstd's, ends early, or would come to more than limit bytes. Panics when the limit is negative.

    ZstdCompressor class

    Public Class ZstdCompressor Implements Coder

    Zstd's bytes made in turn: Add gives what compressing the bytes it takes has made so far, and Finish what's left, which ends a frame, and starts again.

    std/compress/zstd.fb, line 83

    • @PanicsAtCaller Public New(level: Int = 3) constructor #

      A new ZstdCompressor at the level. Panics when it isn't from 1 to 22.

    • Public Method Add(data: UInt8[]): UInt8[] method #

      Compresses data, and gives the Zstd bytes it has made so far, which can be none, as it holds some back to compress with what comes next.

    • Public Method Finish(): UInt8[] method #

      The rest of the bytes, which end the frame, and starts again, for another.

    ZstdDecompressor class

    Public Class ZstdDecompressor Implements Coder

    Zstd's bytes taken in turn, a frame after another: Add gives what the bytes it takes decompress to so far, and Finish what's left once they've all been added, and starts again. Each throws an IOError when the bytes aren't Zstd's or would come to more than the limit, and Finish when they end early.

    std/compress/zstd.fb, line 116

    • @PanicsAtCaller Public New(limit: Int = MOST_BYTES) constructor #

      A new ZstdDecompressor that gives at most limit bytes. Panics when the limit is negative.

    • Public Method Add(data: UInt8[]): UInt8[] Throws IOError method #

      Decompresses data, and gives the bytes it comes to so far. Throws an IOError when the bytes aren't Zstd's, or would come to more than the limit.

    • Public Method Finish(): UInt8[] Throws IOError method #

      The rest of the bytes, once every one is added, and starts again. Throws an IOError when the frame ended early.

    Report an issue with this page or with FutureBlitz on GitHub.