zstd

Zstandard compression library bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_zstd.cC FFI wrapper
c/kit_zstd.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/zstd.kitKit Zstd - Zstandard compression library bindings
tests/zstd.test.kitTests for zstd

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-zstd.git

System Requirements

PlatformCommand
macOSbrew install zstd
Ubuntusudo apt install libzstd-dev
Fedorasudo dnf install libzstd-devel

Usage

import Kit.Zstd as Zstd

main = fn =>
  data = "Hello, World! Hello, World! Hello, World! Hello, World!"
  println ("Original size: " ++ (show (String.length data)))

  # Compress with default level (3)
  match Zstd.compress data
    | Ok compressed ->
      println ("Compressed size: " ++ (show (String.length compressed)))

      # Decompress
      match Zstd.decompress compressed
        | Ok decompressed -> println ("Decompressed: " ++ decompressed)
        | Err e -> println ("Decompress error: " ++ e)
    | Err e -> println ("Compress error: " ++ e)

  # Compress with specific level (1 = fastest, 22 = best ratio)
  match Zstd.compress-level 19 data
    | Ok compressed -> println ("Level 19 size: " ++ (show (String.length compressed)))
    | Err e -> println ("Error: " ++ e)

  # Library info
  println ("Zstd version: " ++ Zstd.version())
  println ("Max compression level: " ++ (show (Zstd.max-level())))

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/zstd/, making it available for import as Kit.Zstd in other projects.

License

This package is released under the MIT License - see LICENSE for details.

Zstandard is released under the BSD 3-Clause License.

Exported Functions & Types

compress

Compress a string using Zstd with the default compression level (3).

Parameters:

Returns:

String -> Result String String

match compress "Hello, World!"
  | Ok compressed -> println "Compressed!"
  | Err e -> println "Error: ${e}"

compress-level

Compress a string using Zstd with a specific compression level.

Levels range from 1 (fastest, least compression) to 22 (slowest, best compression). The default level is 3.

Parameters:

Returns:

Int -> String -> Result String String

match compress-level 19 "Hello, World!"
  | Ok compressed -> println "Highly compressed!"
  | Err e -> println "Error: ${e}"

decompress

Decompress a Zstd-compressed string.

The input must have been compressed with compress or compress-level, which prepend the original size as an 8-byte header.

Parameters:

Returns:

String -> Result String String

match decompress compressed-data
  | Ok original -> println original
  | Err e -> println "Decompression failed: ${e}"

max-level

Get the maximum compression level supported by the library.

Returns:

Int

println "Max level: ${show (max-level())}"

version

Get the Zstd library version as a human-readable string.

Returns:

String

println "Zstd version: ${version()}"