blob: 50c42133fb0d7aaf0b520ba783cf528b4b19a072 [file] [log] [blame]
Andrew Geissler5f350902021-07-23 13:09:54 -04001#
2# SPDX-License-Identifier: GPL-2.0-only
3#
4
5import bb.compress._pipecompress
6import shutil
7
8
9def open(*args, **kwargs):
10 return bb.compress._pipecompress.open_wrap(ZstdFile, *args, **kwargs)
11
12
13class 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"]