tar-diff

module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2026 License: Apache-2.0

README

CI Go Version License codecov

tar-diff

tar-diff is a golang library and set of commandline tools to diff and patch tar files.

pkg/tar-diff and the tar-diff tool take one or more old tar files (optionally compressed) and a new tar file to generate a single file representing the delta between them (a tardiff file).

pkg/tar-patch takes a tardiff file and the uncompressed contents (such as an extracted directory) of the old tar file(s) and reconstructs (binary identically) the new tar file (uncompressed).

Example

$ tar-diff old.tar.gz new.tar.gz delta.tardiff
$ tar xf old.tar.gz -C extracted/
$ tar-patch delta.tardiff extracted/ reconstructed.tar
$ zcat new.tar.gz | shasum
$ shasum reconstructed.tar

Multi-file example

It is sometimes useful to have multiple sources for delta information, such as for example when the sources are container image layers. In this case, you need to provide the old tar files in the order they will be extracted when applying:

$ tar-diff layer1.tar layer2.tar layer3.tar new-layer.tar delta.tardiff
$ tar xf layer1.tar -C extracted/
$ tar xf layer2.tar -C extracted/
$ tar xf layer3.tar -C extracted/
$ tar-patch delta.tardiff extracted/ reconstructed.tar

This handles the case where a file in a later tar file overwrites another.

Partial extraction with prefix filtering

If you only plan to extract certain directories from the old tar files on the target system, you can use --source-prefix to restrict which files can be used as delta sources:

$ tar-diff --source-prefix=blobs/ --source-prefix=config/ old.tar new.tar delta.tardiff
$ tar xf old.tar blobs/ config/ -C extracted/
$ tar-patch delta.tardiff extracted/ reconstructed.tar

This ensures the delta only references files that will be available in the extracted directory.

This is particularly useful for e.g. bootc images, where only the files in the ostree repo will be available on the system. For that case you would run tar-diff with --source-prefix=sysroot/ostree/repo/objects/

Build requirements

  • golang >= 1.25 (see go.mod)
  • make
  • tar
  • diffutils, bzip2, gzip (for tests)

Runtime dependencies

None. The built binaries are self-contained.

The main use case for tar-diff is for more efficient distribution of OCI images. These images are typically transferred as compressed tar files, but the content is referred to and validated by the checksum of the uncompressed content. This makes it possible to use an extracted earlier version of an image in combination with a tardiff file to reconstruct and validate the current version of the image.

Delta compression is based on bsdiff and zstd compression.

The tar-diff file format is described in file-format.md.

License

tar-diff is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Directories

Path Synopsis
cmd
tar-diff command
Package main implements the tar-diff command line tool for creating binary diffs between tar archives.
Package main implements the tar-diff command line tool for creating binary diffs between tar archives.
tar-patch command
Package main implements the tar-patch command line tool for applying binary diffs to tar archives.
Package main implements the tar-patch command line tool for applying binary diffs to tar archives.
pkg
protocol
Package protocol provides shared constants and data structures for tar-diff operations.
Package protocol provides shared constants and data structures for tar-diff operations.
tar-diff
Package tardiff provides functionality for analyzing and creating binary differences between tar archives.
Package tardiff provides functionality for analyzing and creating binary differences between tar archives.
tar-patch
Package tarpatch provides functionality for applying binary patches to tar archives.
Package tarpatch provides functionality for applying binary patches to tar archives.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL