A Rust implementation of the tar archive utility.
Probably not. The tar
binary that came with your OS has more features and has been tested against millions of archives, use it instead.
Building a tool like this is a really good way to learn Rust syntax+features! Some things I learned:
- How to work with raw binary data
- How to create iterators over arbitrary data
- How to parse+validate CLI parameters using StructOpt
- Integration tests using assert_cmd
- Rust's built-in unit tests
- File I/O
- Option and Result types (I love not having to deal with nullable types and exceptions)
Run with --help
to see the list of options:
./rust-tar --help
rust-tar 0.1.1
USAGE:
rust-tar [FLAGS] <file-name>
FLAGS:
-x Extract mode: extract an archive to disk
-h, --help Prints help information
-t List mode: list archive contents
-V, --version Prints version information
ARGS:
<file-name> The path to a tarball
Run with -t
to show file contents (without saving to disk), or -x
to save to disk:
./rust-tar -t test-files/multiple-files.tar
Read all 3072 bytes from tarball successfully
Processing file header: 'ascii.txt'
Decimal checksum: 6310
Calculated checksum: 6310
File size in bytes: 11
File contents: Hello, tar!
Processing file header: 'ascii2.txt'
Decimal checksum: 6354
Calculated checksum: 6354
File size in bytes: 17
File contents: Hello again, tar!