libarchive
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | compression ffi |
| Keywords | archive tar zip gzip compression |
libarchive bindings for reading and writing archive formats in 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_archive.c | C FFI wrapper |
c/kit_archive.h | C header for FFI wrapper |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata and dependencies |
src/libarchive.kit | Kit LibArchive - libarchive bindings for reading and writing archives |
tests/libarchive.test.kit | Tests for libarchive |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-libarchive.gitSystem Requirements
| Platform | Command |
|---|---|
| macOS | brew install libarchive |
| Ubuntu | sudo apt install libarchive-dev |
| Fedora | sudo dnf install libarchive-devel |
Usage
import Kit.LibArchive as LibArchive
main = fn =>
# List entries in an archive
match LibArchive.list "project.tar.gz"
| Ok entries ->
println ("Found " ++ (show (List.length entries)) ++ " entries:")
List.map (fn(e) => println (" " ++ e)) entries
no-op
| Err e -> println ("Error: " ++ e)
# Extract a single file from an archive
match LibArchive.extract-file "project.tar.gz" "README.md"
| Ok contents -> println ("Contents: " ++ contents)
| Err e -> println ("Error: " ++ e)
# Extract entire archive to a directory
match LibArchive.extract "project.tar.gz" "/tmp/output"
| Ok _ -> println "Archive extracted"
| Err e -> println ("Error: " ++ e)
# Create a tar.gz archive from files
match LibArchive.create-tar-gz "/tmp/output.tar.gz" ["kit.toml", "src/main.kit"]
| Ok _ -> println "Archive created"
| Err e -> println ("Error: " ++ e)
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/libarchive/, making it available for import as Kit.LibArchive in other projects.
License
This package is released under the MIT License - see LICENSE for details.
libarchive is released under the BSD 3-Clause License.
Exported Functions & Types
list
List all entry names in an archive file.
Supports tar, zip, 7z, gzip, xz, and many other formats. Format is auto-detected from the file contents.
Parameters:
Returns:
String -> Result [String] String
match list "data.tar.gz"
| Ok entries ->
println ("Found " ++ (show (List.length entries)) ++ " entries")
List.map (fn(e) => println (" " ++ e)) entries
| Err e -> println "Error: ${e}"extract
Extract all entries from an archive to a directory.
The destination directory must already exist. Supports tar, zip, 7z, and many other formats with automatic detection.
Parameters:
Returns:
String -> String -> Result Unit String
match extract "data.tar.gz" "/tmp/output"
| Ok _ -> println "Extracted successfully!"
| Err e -> println "Extraction failed: ${e}"extract-file
Extract a single file from an archive and return its contents as a string.
Parameters:
Returns:
String -> String -> Result String String
match extract-file "data.tar.gz" "README.md"
| Ok contents -> println contents
| Err e -> println "Error: ${e}"create-tar-gz
Create a .tar.gz archive from a list of file paths.
Parameters:
Returns:
String -> [String] -> Result Unit String
files = ["src/main.kit", "src/util.kit", "kit.toml"]
match create-tar-gz "release.tar.gz" files
| Ok _ -> println "Archive created!"
| Err e -> println "Error: ${e}"