1761685d3e8d0594ff580c968874665e64a9a9cb

Author
Filipe Nascimento <flipee@tuta.io>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

extract: add zstd support (#8469)

Diff

 1diff --git a/plugins/extract/README.md b/plugins/extract/README.md
 2index 41b6a61f15b36352df156debd365169706b93446..aca30009719c861cdfa19a254379b3582717bd9a 100644
 3--- a/plugins/extract/README.md
 4+++ b/plugins/extract/README.md
 5@@ -34,15 +34,18 @@ plugins=(... extract)
 6 | `tar.gz`          | Tarball with gzip compression        |
 7 | `tar.xz`          | Tarball with lzma2 compression       |
 8 | `tar.zma`         | Tarball with lzma compression        |
 9+| `tar.zst`         | Tarball with zstd compression        |
10 | `tbz`             | Tarball with bzip compression        |
11 | `tbz2`            | Tarball with bzip2 compression       |
12 | `tgz`             | Tarball with gzip compression        |
13 | `tlz`             | Tarball with lzma compression        |
14 | `txz`             | Tarball with lzma2 compression       |
15+| `tzst`            | Tarball with zstd compression        |
16 | `war`             | Web Application archive (Java-based) |
17 | `xpi`             | Mozilla XPI module file              |
18 | `xz`              | LZMA2 archive                        |
19 | `zip`             | Zip archive                          |
20+| `zst`             | Zstandard file (zstd)                |
21 
22 See [list of archive formats](https://en.wikipedia.org/wiki/List_of_archive_formats) for
23 more information regarding archive formats.
24diff --git a/plugins/extract/_extract b/plugins/extract/_extract
25index 0257ce2314000a9580e7e8edd8c7d673f163d445..47b918b29b952fc56852539c8d46b64ef71f4cb8 100644
26--- a/plugins/extract/_extract
27+++ b/plugins/extract/_extract
28@@ -3,5 +3,5 @@
29 
30 _arguments \
31   '(-r --remove)'{-r,--remove}'[Remove archive.]' \
32-  "*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|deb|gz|ipsw|jar|lzma|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.xz|tar.zma|tbz|tbz2|tgz|tlz|txz|war|whl|xpi|xz|zip)(-.)'" \
33+  "*::archive file:_files -g '(#i)*.(7z|Z|apk|aar|bz2|deb|gz|ipsw|jar|lzma|rar|rpm|sublime-package|tar|tar.bz2|tar.gz|tar.xz|tar.zma|tar.zst|tbz|tbz2|tgz|tlz|txz|tzst|war|whl|xpi|xz|zip|zst)(-.)'" \
34     && return 0
35diff --git a/plugins/extract/extract.plugin.zsh b/plugins/extract/extract.plugin.zsh
36index 27b9e50f172a48667dd5c4a353d6ef02bd2ee7ae..b7d4e3ba7e3fdc27d07f02bc3fe12bda474544e5 100644
37--- a/plugins/extract/extract.plugin.zsh
38+++ b/plugins/extract/extract.plugin.zsh
39@@ -40,6 +40,10 @@ extract() {
40 				tar --lzma --help &> /dev/null \
41 				&& tar --lzma -xvf "$1" \
42 				|| lzcat "$1" | tar xvf - ;;
43+			(*.tar.zst|*.tzst)
44+				tar --zstd --help &> /dev/null \
45+				&& tar --zstd -xvf "$1" \
46+				|| zstdcat "$1" | tar xvf - ;;
47 			(*.tar) tar xvf "$1" ;;
48 			(*.gz) (( $+commands[pigz] )) && pigz -dk "$1" || gunzip -k "$1" ;;
49 			(*.bz2) bunzip2 "$1" ;;
50@@ -59,6 +63,7 @@ extract() {
51 				cd ..; rm *.tar.* debian-binary
52 				cd ..
53 			;;
54+			(*.zst) unzstd "$1" ;;
55 			(*)
56 				echo "extract: '$1' cannot be extracted" >&2
57 				success=1