Anyreader
A library for reading streams of compressed and uncompressed data without knowing the format in advance.
You can use this to recursively read raw data from potentially compressed streams that may contain archives.
Installation:
cargo add anyreader
Example:
The code below will read the contents of a tar.gz archive and print the size of each file. Any archives or compressed files within the archive will also be recursively read:
use ;
use Path;
use File;
use ;
iterate_archive
If you want to iterate archive entries without recursion, use iterate_archive. This function:
- Decompresses outer layers (gzip, zstd, bzip2, xz) to reach the archive
- Iterates archive entries (tar or zip) once
- Returns entries with raw bytes - does NOT recurse into nested archives or decompress entry contents
use iterate_archive;
use File;
use ;
| Behavior | recursive_read |
iterate_archive |
|---|---|---|
| Compression | Recurses through all layers | Recurses to reach archive |
| Nested archives | Recurses into them | Stops, returns as entry |
| Entry content | Auto-decompressed | Raw bytes |
CLI
The anyreader crate also comes with a CLI tool that can be used to read files from the command line. It will
recursively read any archives or compressed files within the input files, and write the decompressed, flattened
contents to the output file in a tar format.
This requires the cli feature: cargo install anyreader -F cli
<INPUT>...
<OUTPUT> Output