summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/compress/zstd.py
blob: 50c42133fb0d7aaf0b520ba783cf528b4b19a072 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#
# SPDX-License-Identifier: GPL-2.0-only
#

import bb.compress._pipecompress
import shutil


def open(*args, **kwargs):
    return bb.compress._pipecompress.open_wrap(ZstdFile, *args, **kwargs)


class ZstdFile(bb.compress._pipecompress.PipeFile):
    def __init__(self, *args, num_threads=1, compresslevel=3, **kwargs):
        self.num_threads = num_threads
        self.compresslevel = compresslevel
        super().__init__(*args, **kwargs)

    def _get_zstd(self):
        if self.num_threads == 1 or not shutil.which("pzstd"):
            return ["zstd"]
        return ["pzstd", "-p", "%d" % self.num_threads]

    def get_compress(self):
        return self._get_zstd() + ["-c", "-%d" % self.compresslevel]

    def get_decompress(self):
        return self._get_zstd() + ["-d", "-c"]