Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright BitBake Contributors |
| 3 | # |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | |
| 7 | import bb.compress._pipecompress |
| 8 | import shutil |
| 9 | |
| 10 | |
| 11 | def open(*args, **kwargs): |
| 12 | return bb.compress._pipecompress.open_wrap(ZstdFile, *args, **kwargs) |
| 13 | |
| 14 | |
| 15 | class ZstdFile(bb.compress._pipecompress.PipeFile): |
| 16 | def __init__(self, *args, num_threads=1, compresslevel=3, **kwargs): |
| 17 | self.num_threads = num_threads |
| 18 | self.compresslevel = compresslevel |
| 19 | super().__init__(*args, **kwargs) |
| 20 | |
| 21 | def _get_zstd(self): |
| 22 | if self.num_threads == 1 or not shutil.which("pzstd"): |
| 23 | return ["zstd"] |
| 24 | return ["pzstd", "-p", "%d" % self.num_threads] |
| 25 | |
| 26 | def get_compress(self): |
| 27 | return self._get_zstd() + ["-c", "-%d" % self.compresslevel] |
| 28 | |
| 29 | def get_decompress(self): |
| 30 | return self._get_zstd() + ["-d", "-c"] |