~egtann/txtar

A Chez Scheme port of Go's txtar package.
bb1b7dfa — Evan Tann a month ago
fix broken link in readme
e92a9d47 — Evan Tann a month ago
refactor file parsing, tests
226e8dda — Evan Tann a month ago
refactor txtar parser to use record-based state management

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~egtann/txtar
read/write
git@git.sr.ht:~egtann/txtar

You can also use your local clone with git send-email.

#txtar

txtar enables you to work with a simple text archive format compatible with Go's txtar. It concatenates files together and allows for a top-level comment.

Math implementation
-- math.h --
#ifndef MATH_H
#define MATH_H

int add(int a, int b);

#endif
-- math.c --
#include "math.h"

int add(int a, int b) {
    return a + b;
}

This format is easy for humans to read and write by hand and is perfect for test data.

#Install

# Install the library.
$ make install

# Add the library directory to your CHEZSCHEMELIBDIRS.
$ export CHEZSCHEMELIBDIRS="$HOME/.local/lib/chez-scheme:$CHEZSCHEMELIBDIRS"

If you want to remove the library from your system, simply run make uninstall.

#Dependencies

This library requires:

;; For using it.
(srfi s13 strings)

;; For running the tests only.
(srfi s64 testing)

You can obtain these libraries and many more via Thunderchez:

$ git clone https://github.com/ovenpasta/thunderchez

# Add the library directory to your CHEZSCHEMELIBDIRS.
$ export CHEZSCHEMELIBDIRS=/path/to/thunderchez

#Usage

All the exports of this library are documented with type expectations. I encourage you to scan the implementation.

A few common example usecases are presented below for convenience:

#Import

To use this library, simply import txtar:

(import (txtar))

#Construct an archive from a list of filenames

(txtar-read-files "Test files" '("test1.txt" "test2.txt"))

#Write text to an archive file

(let* ([files
         (list
           (make-txtar-file "math.h" "#ifndef MATH_H\n#define MATH_H\n\nint add(int a, int b);\n\n#endif")
           (make-txtar-file "math.c" "#include \"math.h\"\n\nint add(int a, int b) {\n    return a + b;\n}"))]
       [archive (make-txtar-archive "Math implementation" files)]
       [output-port (open-output-file "math.txtar")])
  (txtar-write archive output-port)
  (close-output-port output-port))

#Retrieve a file from an archive

(let ([file (txtar-file-ref archive "file-in-the-archive.txt")])
  (if file
    (display "the file existed")
    (display "the file did not exist")))

#License

Copyright (C) 2025 Evan Tann, ParaVoce LLC

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Do not follow this link