diff options
| author | Joshua Watt <JPEWhacker@gmail.com> | 2021-07-14 10:01:57 -0500 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-07-20 18:59:18 +0100 |
| commit | 8410987884fbf5f71a116d4e02763324aa7300f8 (patch) | |
| tree | b6d23fe1c7f3068edf2cf923108f2014576f41ef /bitbake/lib/bb/compress/zstd.py | |
| parent | 75fad23fc06c008a03414a1fc288a8614c6af9ca (diff) | |
| download | poky-8410987884fbf5f71a116d4e02763324aa7300f8.tar.gz | |
bitbake: bitbake: Add piping compression library
Adds a library that implements file-like objects (similar to
gzip.GzipFile) that can stream to arbitrary compression programs. This
is utilized to implement a LZ4 and zstd compression API.
(Bitbake rev: 61c3acd058ea018696bd284b3922d0b458838d05)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/compress/zstd.py')
| -rw-r--r-- | bitbake/lib/bb/compress/zstd.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/bitbake/lib/bb/compress/zstd.py b/bitbake/lib/bb/compress/zstd.py new file mode 100644 index 0000000000..50c42133fb --- /dev/null +++ b/bitbake/lib/bb/compress/zstd.py | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | # | ||
| 2 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 3 | # | ||
| 4 | |||
| 5 | import bb.compress._pipecompress | ||
| 6 | import shutil | ||
| 7 | |||
| 8 | |||
| 9 | def open(*args, **kwargs): | ||
| 10 | return bb.compress._pipecompress.open_wrap(ZstdFile, *args, **kwargs) | ||
| 11 | |||
| 12 | |||
| 13 | class ZstdFile(bb.compress._pipecompress.PipeFile): | ||
| 14 | def __init__(self, *args, num_threads=1, compresslevel=3, **kwargs): | ||
| 15 | self.num_threads = num_threads | ||
| 16 | self.compresslevel = compresslevel | ||
| 17 | super().__init__(*args, **kwargs) | ||
| 18 | |||
| 19 | def _get_zstd(self): | ||
| 20 | if self.num_threads == 1 or not shutil.which("pzstd"): | ||
| 21 | return ["zstd"] | ||
| 22 | return ["pzstd", "-p", "%d" % self.num_threads] | ||
| 23 | |||
| 24 | def get_compress(self): | ||
| 25 | return self._get_zstd() + ["-c", "-%d" % self.compresslevel] | ||
| 26 | |||
| 27 | def get_decompress(self): | ||
| 28 | return self._get_zstd() + ["-d", "-c"] | ||
