fastar
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
- breaking Versions prior to 0.9.0 may contain security vulnerabilities (CVE-2026-32766 and CVE-2026-33056) inherited from underlying Rust crates like `rust-tar`.
- gotcha The `fastar.open` method supports various modes for compression (`w`, `w:gz`, `w:zst`, `r`, `r:`, `r:gz`, `r:zst`). Using the wrong mode for a compressed archive can lead to errors or corrupted data.
Install
-
pip install fastar
Imports
- fastar
import fastar
Quickstart
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()