2015-08-10 19:24:51 +00:00
|
|
|
# tar-split
|
2015-02-20 15:29:48 +00:00
|
|
|
|
2023-03-26 01:00:42 +00:00
|
|
|
![Build Status](https://github.com/vbatts/tar-split/actions/workflows/go.yml/badge.svg)
|
|
|
|
![Lint](https://github.com/vbatts/tar-split/actions/workflows/lint.yml/badge.svg)
|
2017-03-13 22:28:54 +00:00
|
|
|
[![Go Report Card](https://goreportcard.com/badge/github.com/vbatts/tar-split)](https://goreportcard.com/report/github.com/vbatts/tar-split)
|
2015-03-09 18:22:45 +00:00
|
|
|
|
2015-08-18 18:54:32 +00:00
|
|
|
Pristinely disassembling a tar archive, and stashing needed raw bytes and offsets to reassemble a validating original archive.
|
2015-02-20 15:29:48 +00:00
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
## Docs
|
2015-03-09 18:24:00 +00:00
|
|
|
|
2015-08-10 19:29:08 +00:00
|
|
|
Code API for libraries provided by `tar-split`:
|
|
|
|
|
2015-03-09 18:24:00 +00:00
|
|
|
* https://godoc.org/github.com/vbatts/tar-split/tar/asm
|
|
|
|
* https://godoc.org/github.com/vbatts/tar-split/tar/storage
|
|
|
|
* https://godoc.org/github.com/vbatts/tar-split/archive/tar
|
|
|
|
|
2015-08-10 19:29:08 +00:00
|
|
|
## Install
|
|
|
|
|
|
|
|
The command line utilitiy is installable via:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
go get github.com/vbatts/tar-split/cmd/tar-split
|
|
|
|
```
|
|
|
|
|
2015-09-03 19:01:25 +00:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
For cli usage, see its [README.md](cmd/tar-split/README.md).
|
|
|
|
For the library see the [docs](#docs)
|
|
|
|
|
2015-10-16 20:41:09 +00:00
|
|
|
## Demo
|
|
|
|
|
|
|
|
### Basic disassembly and assembly
|
|
|
|
|
2015-10-16 21:05:18 +00:00
|
|
|
This demonstrates the `tar-split` command and how to assemble a tar archive from the `tar-data.json.gz`
|
|
|
|
|
|
|
|
|
2015-10-16 20:41:09 +00:00
|
|
|
![basic cmd demo thumbnail](https://i.ytimg.com/vi/vh5wyjIOBtc/2.jpg?time=1445027151805)
|
|
|
|
[youtube video of basic command demo](https://youtu.be/vh5wyjIOBtc)
|
|
|
|
|
2015-10-16 21:05:18 +00:00
|
|
|
### Docker layer preservation
|
|
|
|
|
|
|
|
This demonstrates the tar-split integration for docker-1.8. Providing consistent tar archives for the image layer content.
|
|
|
|
|
2016-02-29 16:40:38 +00:00
|
|
|
![docker tar-split demo](https://i.ytimg.com/vi_webp/vh5wyjIOBtc/default.webp)
|
2015-10-16 21:05:18 +00:00
|
|
|
[youtube vide of docker layer checksums](https://youtu.be/tV_Dia8E8xw)
|
2015-10-16 20:41:09 +00:00
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
## Caveat
|
2015-02-20 15:29:48 +00:00
|
|
|
|
|
|
|
Eventually this should detect TARs that this is not possible with.
|
|
|
|
|
|
|
|
For example stored sparse files that have "holes" in them, will be read as a
|
|
|
|
contiguous file, though the archive contents may be recorded in sparse format.
|
|
|
|
Therefore when adding the file payload to a reassembled tar, to achieve
|
|
|
|
identical output, the file payload would need be precisely re-sparsified. This
|
2017-09-01 08:45:09 +00:00
|
|
|
is not something I seek to fix immediately, but would rather have an alert that
|
2015-02-20 15:29:48 +00:00
|
|
|
precise reassembly is not possible.
|
2015-02-20 15:30:18 +00:00
|
|
|
(see more http://www.gnu.org/software/tar/manual/html_node/Sparse-Formats.html)
|
2015-02-20 15:29:48 +00:00
|
|
|
|
|
|
|
|
2015-03-05 19:33:05 +00:00
|
|
|
Other caveat, while tar archives support having multiple file entries for the
|
|
|
|
same path, we will not support this feature. If there are more than one entries
|
|
|
|
with the same path, expect an err (like `ErrDuplicatePath`) or a resulting tar
|
|
|
|
stream that does not validate your original checksum/signature.
|
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
## Contract
|
2015-03-09 18:19:40 +00:00
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
Do not break the API of stdlib `archive/tar` in our fork (ideally find an upstream mergeable solution).
|
2015-02-20 15:29:48 +00:00
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
## Std Version
|
2015-02-20 21:12:01 +00:00
|
|
|
|
2018-09-06 00:08:01 +00:00
|
|
|
The version of golang stdlib `archive/tar` is from go1.11
|
2015-08-18 18:54:32 +00:00
|
|
|
It is minimally extended to expose the raw bytes of the TAR, rather than just the marshalled headers and file stream.
|
|
|
|
|
2015-02-20 21:12:01 +00:00
|
|
|
|
2015-08-10 19:29:08 +00:00
|
|
|
## Design
|
2015-02-20 21:12:01 +00:00
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
See the [design](concept/DESIGN.md).
|
2015-03-10 15:19:50 +00:00
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
## Stored Metadata
|
2015-03-10 15:41:20 +00:00
|
|
|
|
|
|
|
Since the raw bytes of the headers and padding are stored, you may be wondering
|
|
|
|
what the size implications are. The headers are at least 512 bytes per
|
|
|
|
file (sometimes more), at least 1024 null bytes on the end, and then various
|
|
|
|
padding. This makes for a constant linear growth in the stored metadata, with a
|
|
|
|
naive storage implementation.
|
|
|
|
|
2015-08-10 19:29:08 +00:00
|
|
|
First we'll get an archive to work with. For repeatability, we'll make an
|
|
|
|
archive from what you've just cloned:
|
|
|
|
|
2015-08-10 20:20:22 +00:00
|
|
|
```bash
|
2015-08-10 19:29:08 +00:00
|
|
|
git archive --format=tar -o tar-split.tar HEAD .
|
|
|
|
```
|
2015-03-10 15:41:20 +00:00
|
|
|
|
2015-08-10 20:20:22 +00:00
|
|
|
```bash
|
|
|
|
$ go get github.com/vbatts/tar-split/cmd/tar-split
|
|
|
|
$ tar-split checksize ./tar-split.tar
|
2015-03-10 15:41:20 +00:00
|
|
|
inspecting "tar-split.tar" (size 210k)
|
|
|
|
-- number of files: 50
|
|
|
|
-- size of metadata uncompressed: 53k
|
|
|
|
-- size of gzip compressed metadata: 3k
|
|
|
|
```
|
|
|
|
|
|
|
|
So assuming you've managed the extraction of the archive yourself, for reuse of
|
|
|
|
the file payloads from a relative path, then the only additional storage
|
|
|
|
implications are as little as 3kb.
|
|
|
|
|
|
|
|
But let's look at a larger archive, with many files.
|
|
|
|
|
2015-08-10 20:20:22 +00:00
|
|
|
```bash
|
2015-03-10 15:41:20 +00:00
|
|
|
$ ls -sh ./d.tar
|
|
|
|
1.4G ./d.tar
|
2015-08-10 20:26:09 +00:00
|
|
|
$ tar-split checksize ~/d.tar
|
2015-03-10 15:41:20 +00:00
|
|
|
inspecting "/home/vbatts/d.tar" (size 1420749k)
|
|
|
|
-- number of files: 38718
|
|
|
|
-- size of metadata uncompressed: 43261k
|
|
|
|
-- size of gzip compressed metadata: 2251k
|
|
|
|
```
|
|
|
|
|
|
|
|
Here, an archive with 38,718 files has a compressed footprint of about 2mb.
|
|
|
|
|
|
|
|
Rolling the null bytes on the end of the archive, we will assume a
|
|
|
|
bytes-per-file rate for the storage implications.
|
|
|
|
|
|
|
|
| uncompressed | compressed |
|
|
|
|
| :----------: | :--------: |
|
|
|
|
| ~ 1kb per/file | 0.06kb per/file |
|
|
|
|
|
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
## What's Next?
|
2015-02-20 20:44:07 +00:00
|
|
|
|
2015-03-09 18:19:40 +00:00
|
|
|
* More implementations of storage Packer and Unpacker
|
|
|
|
* More implementations of FileGetter and FilePutter
|
2015-03-23 20:35:42 +00:00
|
|
|
* would be interesting to have an assembler stream that implements `io.Seeker`
|
2015-02-20 20:44:07 +00:00
|
|
|
|
2015-08-10 20:20:22 +00:00
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
## License
|
2015-02-20 15:29:48 +00:00
|
|
|
|
2015-08-10 19:24:51 +00:00
|
|
|
See [LICENSE](LICENSE)
|