Skip to content

Instantly share code, notes, and snippets.

@WesselAtWork
Last active February 22, 2023 08:02
Show Gist options
  • Select an option

  • Save WesselAtWork/4ab3612c68997623af9376b061a2330c to your computer and use it in GitHub Desktop.

Select an option

Save WesselAtWork/4ab3612c68997623af9376b061a2330c to your computer and use it in GitHub Desktop.
Provides functions for the incremental building or streaming of tar archives
#!/bin/sh
#
# Provides commands for the incremental building or streaming of tar archives
# NOTICE: Do not use compression flags on the input to tarfrg!
# I am not checking you!
# Use in the pipeline instead. e.g. `tarfrg ./tmp/* | tarfrgasm | gzip > archive.tar.gz`
#######################################
# Creates tar file fragments
# Arguments:
# tar arguments
# Forbiden Arguments:
# tar compression arguments (like `-z`)
#######################################
tarfrg() {
#DO NOT USE COMPRESSION!!!
tar c -O "$@" | head -c -1024
}
#######################################
# Asembles tar file fragments form tarfrg
# Input:
# tarfrg output
#######################################
tarfrgasm() {
cat "$@" && head -c 1024 < /dev/zero
}
#######################################
## Usage Examples:
# tarfrg ./file.txt ./file2.txt | tarfrgasm > archive.tar
# tarfrg ./* | tarfrgasm > archive.tar
## Incremental archive building
# tarfrg ./file.txt > archive.tar.frg;
# tarfrg ./file2.txt >> archive.tar.frg;
# tarfrgasm archive.tar.frg > archive.tar;
## Working with applications that generate a stream of files
## filegeneratingapp outputs a stream of filenames to stdout as it writes files to the output-files directory
# filegeneratingapp --output-files /workdone | xargs tarfrg | tarfrgasm | gzip > /writeonly/work.tar.gz
#######################################
#!/bin/sh
tar c -O "$@" | head -c -1024
#!/bin/sh
cat "$@" && head -c 1024 < /dev/zero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment