fastar

0.9.0 · active · verified Sun Apr 05

The fastar library provides high-level Python bindings for the Rust `tar`, `flate2`, and `zstd` crates, offering a high-performance solution for working with compressed and uncompressed tar archives. It is currently at version 0.9.0 and has a consistent release cadence, with updates addressing features and underlying Rust library versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple text file, add it to an uncompressed tar archive using `fastar.open` in write mode, and then extract its contents using read mode. It highlights the basic `append` and `unpack` operations.

from pathlib import Path
import fastar
import os

# Create a dummy file
input_file = Path("file.txt")
input_file.write_text("Hello, Fastar!")

# Create a tar archive (uncompressed)
with fastar.open("archive.tar", "w") as archive:
    archive.append(input_file)

# Extract the tar archive
output_dir = Path("output")
output_dir.mkdir(exist_ok=True)
with fastar.open("archive.tar", "r") as archive:
    archive.unpack(output_dir)

unpacked_file = output_dir / "file.txt"
print(f"Unpacked file content: {unpacked_file.read_text()}")

# Clean up (optional)
input_file.unlink()
Path("archive.tar").unlink()
output_dir.rmdir()

view raw JSON →