Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd-compress: support zstd as an option #3711

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/cmd-compress
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parser = argparse.ArgumentParser()
parser.add_argument("--build", help="Build ID")
parser.add_argument("--artifact", default=[], action='append',
help="Only compress given image ARTIFACT", metavar="ARTIFACT")
parser.add_argument("--compressor", choices=['xz', 'gzip'],
parser.add_argument("--compressor", choices=['xz', 'gzip', 'zstd'],
help="Override compressor to use")
parser.add_argument("--mode",
choices=['compress', 'uncompress'],
Expand All @@ -53,7 +53,7 @@ else:
print(f"Targeting build: {build}")

# common extensions for known compressors
ext_dict = {'xz': '.xz', 'gzip': '.gz'}
ext_dict = {'xz': '.xz', 'gzip': '.gz', 'zstd': '.zst'}


def get_cpu_param(param):
Expand Down Expand Up @@ -115,9 +115,11 @@ def compress_one_builddir(builddir):
img['uncompressed-sha256'] = img['sha256']
img['uncompressed-size'] = img['size']
with open(tmpfile, 'wb') as f:
t = ncpu()
if args.compressor == 'xz':
t = ncpu()
runcmd(['xz', '-c9', f'-T{t}', filepath], stdout=f)
elif args.compressor == 'zstd':
runcmd(['zstd', '-19', '-c', f'-T{t}', filepath], stdout=f)
else:
runcmd(['gzip', f'-{gzip_level}', '-c', filepath], stdout=f)
file_with_ext = file + ext
Expand Down Expand Up @@ -196,6 +198,8 @@ def uncompress_one_builddir(builddir):
if file.endswith('xz'):
t = ncpu()
runcmd(['xz', '-dc', f'-T{t}', filepath], stdout=f)
elif file.endswith('zst'):
runcmd(['zstd', '-dc', filepath], stdout=f)
elif file.endswith('gz'):
runcmd(['gzip', '-dc', filepath], stdout=f)
else:
Expand Down
Loading