smol-tar
A minimal async streaming tar reader/writer. It does not perform filesystem operations itself; it works with async readers, writers, and streams.
Supported formats
Reads:
- Old tar
- GNU tar
- POSIX ustar/pax
- GNU long names and long links
- PAX path metadata, timestamps, numeric ids, sizes, and extended attributes
Writes:
- POSIX ustar/pax
- PAX records for long paths, long link targets, timestamps, numeric ids, symbolic names, sizes, and extended attributes
Not supported
- Sparse files and multi-volume archives (the reader returns an error)
Installation
Runtime selection:
[]
= "0.1"
[]
= { = "0.1", = false, = ["tokio"] }
Reading archives
use ;
use ;
let data = new;
let mut tar = new;
while let Some = tar.next.await
Regular file bodies are streamed. To move on to the next entry, either read the file body to the end or drop the file reader.
Writing archives
use Cursor;
use ;
let sink = new;
let mut tar = new;
tar.write.await?;
let body = new;
tar.write.await?;
tar.finish.await?;
Alongside the direct API, the writer also implements the composable
futures_sink::Sink interface:
Filtering one archive into another sink
use ;
use Cursor;
use *;
let mut input = new;
let mut source = new;
source.send.await?;
source.send.await?;
source.send.await?;
source.send.await?;
source.close.await?;
input.set_position;
let mut output = new;
let mut filtered = new;
new
.try_filter
.forward
.await?;
filtered.close.await?;
output.set_position;
let paths: = new
.map_ok
.try_collect
.await?;
assert_eq!;
Example CLI
The repository also includes a feature-gated example CLI in
examples/smol-tar-bin.
Rationale
For one of my projects, I needed an asynchronous streaming library for reading
and writing tar archives. The project was based on async-std (now
smol), so
tokio-tar was not a sensible fit and I
started with async-tar. Later on I
needed a bit more functionality, but the depth and number of abstractions in
async-tar became rather a lot to hold in my head, so I put together a small,
manageable state machine instead.
The library is properly fuzzed and well covered by tests. It has also seen heavy use in a real internal CI/CD pipeline for some time, and now seems ready for release.
Caveats
- Regular file bodies are streamed. To advance to the next entry, either read the file body to the end or drop the file reader.
- Library paths and example-CLI paths must be valid UTF-8.
Specail thanks
To authors of async-tar for the inspiration.
LICENSE
MIT