zstd
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | compression ffi |
| Keywords | zstd zstandard compression facebook |
Zstandard compression library bindings for Kit
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
c/kit_zstd.c | C FFI wrapper |
c/kit_zstd.h | C header for FFI wrapper |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata and dependencies |
src/zstd.kit | Kit Zstd - Zstandard compression library bindings |
tests/zstd.test.kit | Tests for zstd |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-zstd.gitSystem Requirements
| Platform | Command |
|---|---|
| macOS | brew install zstd |
| Ubuntu | sudo apt install libzstd-dev |
| Fedora | sudo 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())))
mainDevelopment
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis 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()}"