Skip to content

Commit

Permalink
Support bzip3
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeth committed May 15, 2022
1 parent 4c4de88 commit fdd09e5
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 17 deletions.
1 change: 1 addition & 0 deletions archwrap_alias
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ alias uv='u -l'
alias tard='tgzd -t'
alias tbrd='tgzd -B'
alias tbzd='tgzd -b'
alias tb3d='tgzd -3'
alias tlzd='tgzd -l'
alias t7zd='tgzd -7'
alias tlz4='tgzd -4'
Expand Down
6 changes: 6 additions & 0 deletions bin/bzip3best
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
# This script is part of Martin V\"ath's archwrap project.
# (C) Martin V\"ath <martin at mvath.de>
# SPDX-License-Identifier: BSD-3-Clause
set -u
exec bzip3 -e9 ${1+"$@"}
1 change: 1 addition & 0 deletions bin/bzip3d
25 changes: 21 additions & 4 deletions bin/pd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ where option is one of the following:
-o/O select/unselect brotli
-y/Y select/unselect zstd
-b/B select/unselect bzip
-3/2 select/unselect bzip3
-g/G select/unselect gzip
-i/I select/unselect lz4
-7// select/unselect 7z
Expand All @@ -43,11 +44,12 @@ where option is one of the following:
-Q quick: Use gzip instead of zopfli (even if zopfli is available)"
exit ${1:-1}
}
unset zipd tgzd gzipbest brotlibest bzipbest za lz4best \
unset zipd tgzd gzipbest brotlibest bzipbest bzip3best za lz4best \
lzmabest xzbest zstdbest lrzip
tgzapp='tgz'
tbrapp='tbr'
tbzapp='tbz'
tb3app='tb3'
svzapp='t7z'
tz4app='tz4'
lzmapp='tlz'
Expand All @@ -73,6 +75,7 @@ Selectall() {
withtgz=:
withtbr=:
withtbz=:
withtb3=:
withsvz=:
withtz4=:
withlzm=:
Expand All @@ -86,6 +89,7 @@ Selectnone() {
withtgz=false
withtbr=false
withtbz=false
withtb3=false
withsvz=false
withtz4=false
withlzm=false
Expand Down Expand Up @@ -113,7 +117,7 @@ case ${0##*/} in
esac

OPTIND=1
while getopts 'vPqQXdcCSTsnaA7/iIlLrYyWwRNtUzZoObBgGpFf0512486EhH' opt
while getopts 'vPqQXdcCSTsnaA327/iIlLrYyWwRNtUzZoObBgGpFf0512486EhH' opt
do case $opt in
v) verbose=:;;
P) DeselectUnpopular;;
Expand All @@ -122,6 +126,7 @@ do case $opt in
X) tgzapp='tar.gz'
tbrapp='tar.br'
tbzapp='tar.bz2'
tb3app='tar.bz3'
svzapp='tar.7z'
tz4app='tar.lz4'
lzmapp='tar.lzma'
Expand All @@ -144,6 +149,7 @@ do case $opt in
z) withzip=:;;
o) withtbr=:;;
b) withtbz=:;;
3) withtb3=:;;
g) withtgz=:;;
7) withsvz=:;;
i) withtz4=:;;
Expand All @@ -156,6 +162,7 @@ do case $opt in
Z) withzip=false;;
O) withtbr=false;;
B) withtbz=false;;
2) withtb3=false;;
G) withtgz=false;;
/) withsvz=false;;
I) withtz4=false;;
Expand Down Expand Up @@ -243,6 +250,7 @@ Dopack() {
tgznow=$withtgz
tbrnow=$withtbr
tbznow=$withtbz
tb3now=$withtb3
svznow=$withsvz
tz4now=$withtz4
lzmnow=$withlzm
Expand All @@ -254,15 +262,16 @@ Dopack() {
$tgznow && test -s "$destname.$tgzapp" && tgznow=false
$tbrnow && test -s "$destname.$tbrapp" && tbrnow=false
$tbznow && test -s "$destname.$tbzapp" && tbznow=false
$tb3now && test -s "$destname.$tb3app" && tb3now=false
$svznow && test -s "$destname.$svzapp" && svznow=false
$tz4now && test -s "$destname.$tz4app" && tz4now=false
$lzmnow && test -s "$destname.$lzmapp" && lzmnow=false
$txznow && test -s "$destname.$txzapp" && txznow=false
$tzsnow && test -s "$destname.$txzapp" && tzsnow=false
$lrznow && test -s "$destname.$lrzapp" && lrznow=false
fi
if $tgznow || $tbrnow || $tbznow || $svznow || $tz4now || $lzmnow || \
$txznow || $tzsnow || $lrznow
if $tgznow || $tbrnow || $tbznow || $tb3now || $svznow || $tz4now || \
$lzmnow || $txznow || $tzsnow || $lrznow
then tarnow=:
fi
$preserv && $tarnow && test -s "$destname.tar" && tarnow=false
Expand Down Expand Up @@ -304,6 +313,14 @@ Dopack() {
|| Errunp 'bzip2' "$nameb"
fi
Compare
nameb=$destname.$tb3app
if $tb3now
then EchoCond "Creating $nameb"
OptExternal bzip3best
"$bzip3best" -c -- "$destname.tar" >|"$nameb" \
|| Errunp 'bzip3' "$nameb"
fi
Compare
nameb=$destname.$svzapp
if $svznow
then EchoCond "Creating $nameb"
Expand Down
1 change: 1 addition & 0 deletions bin/tb3d
21 changes: 17 additions & 4 deletions bin/tgzd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Create archive ./zipdir.tgz with contents of zipdir
-g use zopfli (archivename is ./zipdir.tgz or ./zipdir.tar.gz)
-Q quick: Use gzip instead of zopfli (even if zopfli is available)
-b use bzip2 (archivename is ./zipdir.tbz or ./zipdir.tar.bz2)
-3 use bzip3 (archivename is ./zipdir.tb3 or ./zipdir.tar.bz3)
-l use lzma (archivename is ./zipdir.tlz or ./zipdir.tar.lzma)
-L use xz (archivename is ./zipdir.txz or ./zipdir.tar.xz)
-4 use lz4 (archivename is ./zipdir.tz4 or ./zipdir.tar.lz4)
Expand Down Expand Up @@ -85,6 +86,11 @@ case ${0##*/} in
*lz*)
comp=l
xnames=:;;
*tb*3*)
comp=3;;
*bz*3*)
comp=3
xnames=:;;
*tbz*)
comp=b;;
*bz*)
Expand All @@ -109,7 +115,7 @@ case ${0##*/} in
comp=;;
esac
OPTIND=1
while getopts 'qQAF@:R:SETcCfdDnBzbg74lLzmrtpPsXxhH' opt
while getopts 'qQAF@:R:SETcCfdDnBzbg734lLzmrtpPsXxhH' opt
do case $opt in
q) quiet=:;;
Q) quick=:;;
Expand Down Expand Up @@ -137,6 +143,7 @@ do case $opt in
[lzm]) comp=l;;
L) comp=x;;
7) comp=7;;
3) comp=3;;
4) comp=4;;
r) comp=r;;
X) xnames=:;;
Expand All @@ -151,8 +158,8 @@ do case $opt in
done
shift $(( $OPTIND - 1 ))

unset tarprg xzbest brotlibest bzipbest gzipbest sevenzbest lzmabest lrzip \
zstdbest lz4best
unset tarprg xzbest brotlibest bzipbest bzip3best gzipbest sevenzbest lzmabest \
lrzip zstdbest lz4best

if $calc_version_only
then CalcGnuTarVersion && printf '%s' "$GNUTARVERSION"
Expand Down Expand Up @@ -206,7 +213,9 @@ else ! $xattr || ! $tar_knows_xattr || Push taropts '--xattrs'
B) OptExternal brotlibest
Push taropts '--use-compress-program' "$brotlibest";;
b) OptExternal bzipbest
Push taropts '--use-compress-program' "$bzipbest";;
Push taropts '--use-compress-program' "$bzip3best";;
3) OptExternal bzip3best
Push taropts '--use-compress-program' "$bzip3best";;
z) OptExternal zstdbest
Push taropts '--use-compress-program' "$zstdbest";;
g) CalcGzipbest $quick
Expand All @@ -229,6 +238,7 @@ then case $comp in
g) ext='tar.gz';;
B) ext='tar.br';;
b) ext='tar.bz2';;
3) ext='tar.bz3';;
z) ext='tar.zst';;
7) ext='tar.7z';;
4) ext='tar.lz4';;
Expand All @@ -241,6 +251,7 @@ else case $comp in
g) ext='tgz';;
B) ext='tbr';;
b) ext='tbz';;
3) ext='tb3';;
z) ext='tzs';;
7) ext='t7z';;
4) ext='tz4';;
Expand Down Expand Up @@ -346,6 +357,8 @@ DoDir() {
"$brotlibest" -o "$name.$ext" -- "$archive";;
b) OptExternal bzipbest
"$bzipbest" -k -c -- "$archive" >|"$name.$ext";;
3) OptExternal bzip3best
"$bzip3best" -c -- "$archive" >|"$name.$ext";;
z) OptExternal zstdbest
"$zstdbest" -o "$name.$ext" <"$archive";;
7) OptExternal sevenzbest 7zbest
Expand Down
50 changes: 43 additions & 7 deletions bin/u
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ Getf() {
for i in '' .tar .TAR
do for j in \
z br bro brotli tbr zst zstd tzs tzst tzstd \
bz2 bz tbz2 tbz gz tgz taz dir tl4 tz4 tlz4 lz4 \
7z t7z lz lzm lzma xz tlz txz lrz tlr tlrz lha lzh \
arj arz zip jar xpi crate cra apk okular rar \
bz2 bz3 bz tbz2 tbz3 tb3 tbz gz tgz taz dir tl4 tz4 \
tlz4 lz4 7z t7z lz lzm lzma xz tlz txz lrz tlr tlrz \
lha lzh arj arz zip jar xpi crate cra apk okular rar \
Z BR BRO BROTLI TBR ZST ZSTD TZS TZST TZSTD \
BZ2 BZ TBZ2 TBZ GZ TGZ TAZ DIR TL4 TZ4 TLZ4 LZ4 \
7Z T7Z LZ LZM LZMA XZ TLZ TXZ LRZ TLR TLRZ LHA LZH \
ARJ ARZ ZIP JAR XPI CRATE CRA APK OKULAR RAR
BZ2 BZ3 BZ TBZ2 TBZ3 TB3 TBZ GZ TGZ TAZ DIR TL4 TZ4 \
TLZ4 LZ4 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
test -f "$f" && return
done
Expand Down Expand Up @@ -232,6 +232,9 @@ DoCases() {
*.tbz|*.tbz2|*.TBZ|*.TBZ2)
typ='tar.bz2'
full=:;;
*.tb3|*.tbz3|*.TB3|*.TBZ3)
typ='tar.bz3'
full=:;;
*.tlz|*.TLZ)
typ='tar.lzma'
full=:;;
Expand All @@ -252,6 +255,8 @@ DoCases() {
typ='zst';;
*.lz4|*.Lz4)
typ='lz4';;
*.bz3|*.BZ3)
typ='bz3';;
*.bz|*.bz2|*.BZ|*.BZ2)
typ='bz2';;
*.lm|*.lzm|*.lzma|*.LM|*.LZM|*.LZMA)
Expand Down Expand Up @@ -297,7 +302,7 @@ DoCases() {
return 0
}

unset bzip brotli zstdbest lz4 gzip lzma xz lrzip za unzip unarj lha unrar
unset bzip bzip3 brotli zstdbest lz4 gzip lzma xz lrzip za unzip unarj lha unrar
DoIt() {
case $typ in
tar)
Expand Down Expand Up @@ -404,6 +409,24 @@ tar.bz2)
fi;;
t*) "$bzip" -t -v -- "$f";;
esac || MyErr;;
tar.bz3)
OptExternal bzip3
case $mode in
u*) IntoDir || return
eval "set -- a $taropts"
shift
if $tar_knows_use_compress_program
then "$tarprg" -x $verboseopt $taruse "$bzip3" ${1+"$@"} -f "$f"
else "$bzip3" -d -c -- "$f" | \
"$tarprg" -x $verboseopt ${1+"$@"} -f -
fi;;
s*) if $tar_knows_use_compress_program
then "$tarprg" -t $verbose $taruse "$bzip3" -f "$f"
else "$bzip3" -d -c -- "$f" | \
"$tarprg" -t $verbose -f -
fi;;
t*) "$bzip3" -t -- "$f" && echo "$f OK";;
esac || MyErr;;
tar.lzma)
OptExternal lzma
case $mode in
Expand Down Expand Up @@ -527,6 +550,19 @@ bz2)
s*) "$bzip" -l -v -- "$f";;
t*) "$bzip" -t -v -- "$f";;
esac || MyErr;;
bz3)
OptExternal bzip3
case $mode in
u*) IntoDir || return
if $mdir
then x=$name.bz3
ln -s -- "$f" "$x" || cp -a -- "$f" "$x" \
&& "$bzip3" -d -- "$x"
else "$bzip3" -d -c -- "$f" >"$pwdname"
fi;;
s*) MyErrNot;;
t*) "$bzip3" -t -- "$f" && echo "$f OK";;
esac || MyErr;;
lzma)
OptExternal lzma
case $mode in
Expand Down
2 changes: 2 additions & 0 deletions zsh/_pd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ _arguments -s -S -A '-*' : \
'-G[unselect gzip]' \
'-i[select lz4]' \
'-I[unselect lz4]' \
'-3[select bzip3]' \
'-2[unselect bzip3]' \
'-7[select 7z]' \
'-/[unselect 7z]' \
'-l[select lzma]' \
Expand Down
3 changes: 2 additions & 1 deletion zsh/_tgzd
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ _arguments -s -S -A '-*' : \
'-g[use gzip (appendix .tgz or .tar.gz)]' \
'-B[use brotli (appendix .tbr or .tar.br)]' \
'-b[use bzip2 (appendix .tbz or .tar.bz2)]' \
'-3[use bz3 (appendix .tb3 or .tar.bz3)]' \
'-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)]' \
'-4[use lz4 (appendix .tz4 or .tar.lz4)]' \
'-r[use lrzip (appendix .tlr or .tar.lrz)]' \
'-t[use Tar (appendix .tar)]' \
'-t[use tar (appendix .tar)]' \
'-X[use long names (appendix .tar.gz over .tgz)]' \
'-x[use short names (appendix .tgz over .tar.gz)]' \
'-A[store extended attributes]' \
Expand Down
2 changes: 1 addition & 1 deletion zsh/_u
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ _arguments -s -S -A '-*' : \
'-p[ignore GNUTARVERSION]' \
'-P[print output for GNUTARVERSION]' \
'-q[quiet]' \
'*:archives:_files -g "*.(tar|TAR|z|br|bro|brotli|tbr|zst|zstd|tzst|tzstd|tzs|tl4|tz4|tlz4|lz4|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|BR|BRO|BROTLI|TBR|ZST|ZSTD|TZST|TZSTD|TZS|TL4|TZ4|TLZ4|LZ4|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|br|bro|brotli|tbr|zst|zstd|tzst|tzstd|tzs|tl4|tz4|tlz4|lz4|bz3|bz2|bz|tbz3|tbz2|tb3|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|BR|BRO|BROTLI|TBR|ZST|ZSTD|TZST|TZSTD|TZS|TL4|TZ4|TLZ4|LZ4|BZ3|BZ2|BZ|TBZ3|TBZ2|TB3|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 fdd09e5

Please sign in to comment.