pack : add support for xz and gz types.

This commit is contained in:
Dmitry Voronin 2023-11-14 06:13:26 +03:00
parent c9eb75335a
commit b20b55531f

View file

@ -42,6 +42,11 @@ pack()
"zip") "zip")
_pack_zip "${@}" _pack_zip "${@}"
;; ;;
"gz")
_pack_gz "${@}"
;;
"xz")
_pack_xz "${@}"
esac esac
# actions on error. # actions on error.
@ -81,6 +86,9 @@ unpack()
# unpack file type. # unpack file type.
local type="${target##*.}" local type="${target##*.}"
[[ "${target}" =~ .tar.gz$ ]] && type="tar.gz"
[[ "${target}" =~ .tar.xz$ ]] && type="tar.xz"
# unpack content. # unpack content.
case "${type,,}" in case "${type,,}" in
"zip") "zip")
@ -89,10 +97,10 @@ unpack()
"7z") "7z")
_unpack_7z "${target}" _unpack_7z "${target}"
;; ;;
"tgz"|"gz") "tgz"|"tar.gz")
_unpack_tgz "${target}" _unpack_tgz "${target}"
;; ;;
"txz"|"xz") "txz"|"tar.xz")
_unpack_txz "${target}" _unpack_txz "${target}"
;; ;;
"tar") "tar")
@ -104,6 +112,12 @@ unpack()
"rar") "rar")
_unpack_rar "${target}" _unpack_rar "${target}"
;; ;;
"xz")
_unpack_xz "${target}"
;;
"gz")
_unpack_gz "${target}"
;;
*) *)
echo -e "${color_yellow}${target}: format not supported.${color_default}" echo -e "${color_yellow}${target}: format not supported.${color_default}"
return 2 return 2
@ -152,40 +166,60 @@ _pack_tar()
tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') > "${1}" tar -c "${@:2}" | pv -s $(du -csb "${@:2}" | sed -n -e '$p' | awk '{print $1}') > "${1}"
} }
_pack_gz()
{
pv "${2}" | gzip -1 > "${1}"
}
_pack_xz()
{
pv "${2}" | xz -9e > "${1}"
}
_unpack_zip() _unpack_zip()
{ {
unzip "${@}" unzip "${1}"
} }
_unpack_7z() _unpack_7z()
{ {
7za x "${@}" 7za x "${1}"
} }
_unpack_tgz() _unpack_tgz()
{ {
pv "${@}" | gzip -d | tar -xf - pv "${1}" | gzip -d | tar -xf -
} }
_unpack_txz() _unpack_txz()
{ {
pv "${@}" | xz -d | tar -xf - pv "${1}" | xz -d | tar -xf -
} }
_unpack_tar() _unpack_tar()
{ {
pv "${@}" | tar -xf - pv "${1}" | tar -xf -
} }
_unpack_iso() _unpack_iso()
{ {
7za x "${@}" 7za x "${1}"
} }
_unpack_rar() _unpack_rar()
{ {
unrar x "${@}" unrar x "${1}"
}
_unpack_gz()
{
pv "${1}" | gzip -d > "${1%.gz}"
}
_unpack_xz()
{
pv "${1}" | xz -d > "${1%.xz}"
} }
# export functions. # export functions.
export -f pack unpack _pack_tgz _pack_txz _pack_tar _pack_zip _unpack_zip _unpack_7z _unpack_tgz _unpack_txz _unpack_tar _pack_error _unpack_iso _unpack_rar export -f pack unpack _pack_tgz _pack_txz _pack_tar _pack_zip _unpack_zip _unpack_7z _unpack_tgz _unpack_txz _unpack_tar _pack_error _unpack_iso _unpack_rar _pack_gz _pack_xz _unpack_gz _unpack_xz