libarchive

libarchive bindings for reading and writing archive formats in 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_archive.cC FFI wrapper
c/kit_archive.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/libarchive.kitKit LibArchive - libarchive bindings for reading and writing archives
tests/libarchive.test.kitTests for libarchive

Dependencies

No Kit package dependencies.

Installation

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

System Requirements

PlatformCommand
macOSbrew install libarchive
Ubuntusudo apt install libarchive-dev
Fedorasudo 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)

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/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}"