Skip to content

Commit

Permalink
Support zstd
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeth committed Aug 26, 2017
1 parent f0ee2c8 commit 0796b48
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 17 deletions.
2 changes: 2 additions & 0 deletions archwrap_alias
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ alias brod='tgzd -BX'
alias bzipd='tgzd -bX'
alias lzmad='tgzd -lX'
alias txzd='tgzd -L'
alias tzsd='tgzd -z'
alias tzstd='tgzd -zX'
alias xzd='tgzd -LX'
alias 7zd='tgzd -7X'
alias lrzd='tgzd -rX'
Expand Down
24 changes: 19 additions & 5 deletions bin/tgzd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Create archive ./zipdir.tgz with contents of zipdir
-L use xz (archivename is ./zipdir.txz or ./zipdir.tar.xz)
-7 use 7z (archivename is ./zipdir.t7z or ./zipdir.tar.7z)
-r use lrzip (archivename is ./zipdir.tlr or ./zipdir.tar.lrz)
-z use zstd (archivename is ./zipdir.tzs or ./zipdir.tar.zst)
-t use Tar only (archivename is ./zipdir.tar)
-X use long names (.tar.gz instead of .tgz etc)
-x use short names (.tgz instead of .tar.gz etc)
Expand Down Expand Up @@ -67,6 +68,11 @@ case ${0##*/} in
*xz*)
comp=x
xnames=:;;
*tzst*)
comp=z
xnames=:;;
*tzs*)
comp=z;;
*bzip*|*.*bz*)
comp=b
xnames=:;;
Expand Down Expand Up @@ -95,7 +101,7 @@ case ${0##*/} in
comp=;;
esac
OPTIND=1
while getopts 'qQAF@:R:SETcCfdDnBbg7lLzmrtpPsXxhH' opt
while getopts 'qQAF@:R:SETcCfdDnBzbg7lLzmrtpPsXxhH' opt
do case $opt in
q) quiet=:;;
Q) quick=:;;
Expand All @@ -117,6 +123,7 @@ do case $opt in
P) calc_version_only=:;;
s) sparse=;;
B) comp=B;;
B) comp=z;;
b) comp=b;;
g) comp=g;;
[lzm]) comp=l;;
Expand All @@ -135,7 +142,7 @@ do case $opt in
done
shift $(( $OPTIND - 1 ))

unset tarprg xzbest brotlibest bzipbest gzipbest sevenzbest lzmabest lrzip
unset tarprg xzbest brotlibest bzipbest gzipbest sevenzbest lzmabest lrzip zstdbest

if $calc_version_only
then CalcGnuTarVersion && printf '%s' "$GNUTARVERSION"
Expand Down Expand Up @@ -176,7 +183,8 @@ then Push taropts '-H=exustar'
b) Push taropts '-bz'
STAR_COMPRESS_FLAG='-9'
export STAR_COMPRESS_FLAG;;
[xlr7]) tarcomp=false;;
[xlrz7])
tarcomp=false;;
esac
else ! $xattr || ! $tar_knows_xattr || Push taropts '--xattrs'
! $tar_knows_numeric_owner || ! $ownernum || Push taropts '--numeric-owner'
Expand All @@ -189,6 +197,8 @@ else ! $xattr || ! $tar_knows_xattr || Push taropts '--xattrs'
Push taropts '--use-compress-program' "$brotlibest";;
b) OptExternal bzipbest
Push taropts '--use-compress-program' "$bzipbest";;
z) OptExternal zstdbest
Push taropts '--use-compress-program' "$zstdbest";;
g) CalcGzipbest $quick
if [ "$gziptext" = gzip ]
then Push taropts '--use-compress-program' "$gzipbest"
Expand All @@ -207,6 +217,7 @@ then case $comp in
g) ext='tar.gz';;
B) ext='tar.bro';;
b) ext='tar.bz2';;
z) ext='tar.zst';;
7) ext='tar.7z';;
l) ext='tar.lzma';;
x) ext='tar.xz';;
Expand All @@ -217,6 +228,7 @@ else case $comp in
g) ext='tgz';;
B) ext='tbr';;
b) ext='tbz';;
z) ext='tzs';;
7) ext='t7z';;
l) ext='tlz';;
x) ext='txz';;
Expand Down Expand Up @@ -278,14 +290,14 @@ MainLoop() {
}

StripDirname() {
for strip in taz tgz tbz dir tlz tlrz tlr
for strip in taz tgz tbz dir tlz tlrz tlr tzst tzs tbr tbro
do case $dirname in
*."$strip")
dirname=${dirname%.*}
return;;
esac
done
for strip in z gz bz bz2 7z t7z lz lzm lzma lrz
for strip in z gz bz bz2 7z t7z lz lzm lzma lrz zst bro
do case $dirname in
*.tar."$strip")
dirname=${dirname%.*.*}
Expand Down Expand Up @@ -320,6 +332,8 @@ DoDir() {
"$brotlibest" --input "$archive" --output "$name.$ext";;
b) OptExternal bzipbest
"$bzipbest" -k -c -- "$archive" >"$name.$ext";;
z) OptExternal zstdbest
"$zstdbest" -o "$name.$ext" -- "$archive";;
7) OptExternal sevenzbest 7zbest
"$sevenzbest" <"$archive" >"$name.$ext";;
l) OptExternal lzmabest
Expand Down
1 change: 1 addition & 0 deletions bin/tzsd
1 change: 1 addition & 0 deletions bin/tzstd
47 changes: 38 additions & 9 deletions bin/u
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ Getf() {
test -f "$f" && return
for i in '' .tar .TAR
do for j in \
z bro brotli tbr bz2 bz tbz2 tbz gz tgz taz dir \
z bro brotli tbr zst zstd tzs tzst tzstd \
bz2 bz tbz2 tbz gz tgz taz dir \
7z t7z lz lzm lzma xz tlz txz lrz tlr tlrz lha lzh \
arj arz zip jar xpi crate cra apk okular rar \
Z BRO BROTLI TBZ BZ2 BZ TBZ2 TBZ GZ TGZ TAZ DIR \
Z BRO BROTLI TBR ZST ZSTD TZS TZST TZSTD \
BZ2 BZ TBZ2 TBZ GZ TGZ TAZ DIR \
7Z T7Z LZ LZM LZMA XZ TLZ TXZ LRZ TLR TLRZ LHA LZH \
ARJ ARZ ZIP JAR XPI CRATE CRA APK OKULAR RAR
do f=$1$i.$j
Expand Down Expand Up @@ -219,6 +221,9 @@ DoCases() {
*.tbr|*.TBR)
typ='tar.bro'
full=:;;
*.tzs|*.tzst|*.tzstd|*.TZS|*.TZST|*.TZSTD)
typ='tar.zst'
full=:;;
*.tbz|*.tbz2|*.TBZ|*.TBZ2)
typ='tar.bz2'
full=:;;
Expand All @@ -238,6 +243,8 @@ DoCases() {
typ='gz';;
*.bro|*.brotli|*.BRO|*.BROTLI)
typ='bro';;
*.zst|*.zstd|*.ZST|*.ZSTD)
typ='zst';;
*.bz|*.bz2|*.BZ|*.BZ2)
typ='bz2';;
*.lm|*.lzm|*.lzma|*.LM|*.LZM|*.LZMA)
Expand Down Expand Up @@ -283,7 +290,7 @@ DoCases() {
return 0
}

unset bzip bro gzip lzma xz lrzip za unzip unarj lha unrar
unset bzip bro zstd gzip lzma xz lrzip za unzip unarj lha unrar
DoIt() {
case $typ in
tar)
Expand Down Expand Up @@ -334,6 +341,24 @@ tar.bro)
fi || MyErr;;
t*) MyErrNot;;
esac;;
tar.zst)
OptExternal zstd
case $mode in
u*) IntoDir || return
eval "set -- a $taropts"
shift
if $tar_knows_use_compress_program
then "$tarprg" -x $verboseopt $taruse "$zstd" ${1+"$@"} -f "$f"
else "$zstd" -d --stdout -- "$f" | \
"$tarprg" -x $verboseopt ${1+"$@"} -f -
fi || MyErr;;
s*) if $tar_knows_use_compress_program
then "$tarprg" -t $verbose $taruse "$zstd" -f "$f"
else "$zstd" -d --stdout -- "$f" | \
"$tarprg" -t $verbose -f -
fi || MyErr;;
t*) "$zstd" -t -v -- "$f";;
esac;;
tar.bz2)
OptExternal bzip bzip2
case $mode in
Expand Down Expand Up @@ -445,20 +470,24 @@ bro)
OptExternal bro
case $mode in
u*) IntoDir || return
if $mdir
then x=$name.bro
"$bro" --decompress --input "$x" --output "$pwdname"
else "$bro" --decompress --input "$f" --output "$pwdname"
fi || MyErr;;
"$bro" --decompress --input "$f" --output "$pwdname" || MyErr;;
s*) MyErrNot;;
t*) MyErrNot;;
esac;;
zst)
OptExternal zstd
case $mode in
u*) IntoDir || return
"$zstd" --d -o "$pwdname" -- "$f" || MyErr;;
s*) "$zstd" -l -v -- "$f";;
t*) "$zstd" -t -v -- "$f";;
esac;;
bz2)
OptExternal bzip bzip2
case $mode in
u*) IntoDir || return
if $mdir
then x=$name.gz
then x=$name.bz2
ln -s -- "$f" "$x" || cp -a -- "$f" "$x" \
&& "$bzip" -d -- "$x"
else "$bzip" -d -k -c -- "$f" >"$pwdname"
Expand Down
4 changes: 4 additions & 0 deletions bin/zstdbest
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
# This script is part of Martin V\"ath's archwrap project.
set -u
exec zstd --ultra -22 ${1+"$@"}
2 changes: 1 addition & 1 deletion zsh/_2pd
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ _arguments -S -A '-*' : \
'-r[rename directories rcs into RCS (requires mmv)]' \
'-q[quiet]' \
'-v[verbose]' \
'*:archives:_files -g "*.(tar|TAR|z|bro|brotli|tbr|bz2|bz|tbz2|tbz|gz|tgz|taz|dir|7z|t7z|lz|lzm|lzma|xz|tlz|txz|lrz|tlr|tlrz|lha|lzh|arj|arz|zip|jar|xpi|crate|cra|apk|okular|rar|Z|BRO|BROTLI|TBR|BZ2|BZ|TBZ2|TBZ|GZ|TGZ|TAZ|DIR|7Z|T7Z|LZ|LZM|LZMA|XZ|TLZ|TXZ|LRZ|TLR|TLRZ|LHA|LZH|ARJ|ARZ|ZIP|JAR|XPI|CRATE|CRA|APK|OKULAR|RAR)(-.)"'
'*:archives:_files -g "*.(tar|TAR|z|bro|brotli|tbr|zst|zstd|tzst|tzstd|tzs|bz2|bz|tbz2|tbz|gz|tgz|taz|dir|7z|t7z|lz|lzm|lzma|xz|tlz|txz|lrz|tlr|tlrz|lha|lzh|arj|arz|zip|jar|xpi|crate|cra|apk|okular|rar|Z|BRO|BROTLI|TBR|ZST|ZSTD|TZST|TZSTD|TZS|BZ2|BZ|TBZ2|TBZ|GZ|TGZ|TAZ|DIR|7Z|T7Z|LZ|LZM|LZMA|XZ|TLZ|TXZ|LRZ|TLR|TLRZ|LHA|LZH|ARJ|ARZ|ZIP|JAR|XPI|CRATE|CRA|APK|OKULAR|RAR)(-.)"'
3 changes: 2 additions & 1 deletion zsh/_tgzd
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#compdef 7zd brod bzipd gzipd lrzd lzmad t7zd tard tbrd tbzd tgzd tlrd tlzd txzd xzd
#compdef 7zd brod bzipd tzsd tzstd gzipd lrzd lzmad t7zd tard tbrd tbzd tgzd tlrd tlzd txzd xzd
_arguments -s -S -A '-*' : \
'(* -)'{'-h','-H'}'[help]' \
'-R+[store output in PATH; use e.g. -R - for piping to stdout]:output-path:_files -/' \
'-g[use gzip (appendix .tgz or .tar.gz)]' \
'-B[use brotli (appendix .tbr or .tar.bro)]' \
'-b[use bzip2 (appendix .tbz or .tar.bz2)]' \
'-z[use zstd (appendix .tzs or .tar.zst)]' \
'-l[use lzma (appendix .tlz or .tar.lzma)]' \
'-L[use xz (appendix .txz or .tar.xz)]' \
'-7[use 7z (appendix .t7z or .tar.7z)]' \
Expand Down
2 changes: 1 addition & 1 deletion zsh/_u
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ _arguments -s -S -A '-*' : \
'-p[ignore GNUTARVERSION]' \
'-P[print output for GNUTARVERSION]' \
'-q[quiet]' \
'*:archives:_files -g "*.(tar|TAR|z|bro|brotli|tbr|bz2|bz|tbz2|tbz|gz|tgz|taz|dir|7z|t7z|lz|lzm|lzma|xz|tlz|txz|lrz|tlr|tlrz|lha|lzh|arj|arz|zip|jar|xpi|crate|cra|apk|okular|rar|Z|BRO|BROTLI|TBR|BZ2|BZ|TBZ2|TBZ|GZ|TGZ|TAZ|DIR|7Z|T7Z|LZ|LZM|LZMA|XZ|TLZ|TXZ|LRZ|TLR|TLRZ|LHA|LZH|ARJ|ARZ|ZIP|JAR|XPI|CRATE|CRA|APK|OKULAR|RAR)(-.)"'
'*:archives:_files -g "*.(tar|TAR|z|bro|brotli|tbr|zst|zstd|tzst|tzstd|tzs|bz2|bz|tbz2|tbz|gz|tgz|taz|dir|7z|t7z|lz|lzm|lzma|xz|tlz|txz|lrz|tlr|tlrz|lha|lzh|arj|arz|zip|jar|xpi|crate|cra|apk|okular|rar|Z|BRO|BROTLI|TBR|ZST|ZSTD|TZST|TZSTD|TZS|BZ2|BZ|TBZ2|TBZ|GZ|TGZ|TAZ|DIR|7Z|T7Z|LZ|LZM|LZMA|XZ|TLZ|TXZ|LRZ|TLR|TLRZ|LHA|LZH|ARJ|ARZ|ZIP|JAR|XPI|CRATE|CRA|APK|OKULAR|RAR)(-.)"'

0 comments on commit 0796b48

Please sign in to comment.