Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
p = zstd.ZstdCompressionParameters(compression_level=-1)
self.assertEqual(p.compression_level, -1)
p = zstd.ZstdCompressionParameters(compression_level=-2)
self.assertEqual(p.compression_level, -2)
p = zstd.ZstdCompressionParameters(force_max_window=True)
self.assertEqual(p.force_max_window, 1)
p = zstd.ZstdCompressionParameters(enable_ldm=True)
self.assertEqual(p.enable_ldm, 1)
p = zstd.ZstdCompressionParameters(ldm_hash_log=7)
self.assertEqual(p.ldm_hash_log, 7)
p = zstd.ZstdCompressionParameters(ldm_min_match=6)
self.assertEqual(p.ldm_min_match, 6)
p = zstd.ZstdCompressionParameters(ldm_bucket_size_log=7)
self.assertEqual(p.ldm_bucket_size_log, 7)
p = zstd.ZstdCompressionParameters(ldm_hash_rate_log=8)
self.assertEqual(p.ldm_hash_every_log, 8)
self.assertEqual(p.ldm_hash_rate_log, 8)
def test_estimated_compression_context_size(
self, windowlog, chainlog, hashlog, searchlog, minmatch, targetlength, strategy
):
if minmatch == zstd.MINMATCH_MIN and strategy in (
zstd.STRATEGY_FAST,
zstd.STRATEGY_GREEDY,
):
minmatch += 1
elif minmatch == zstd.MINMATCH_MAX and strategy != zstd.STRATEGY_FAST:
minmatch -= 1
p = zstd.ZstdCompressionParameters(
window_log=windowlog,
chain_log=chainlog,
hash_log=hashlog,
search_log=searchlog,
min_match=minmatch,
target_length=targetlength,
strategy=strategy,
)
size = p.estimated_compression_context_size()
p = zstd.ZstdCompressionParameters(threads=4)
self.assertEqual(p.threads, 4)
p = zstd.ZstdCompressionParameters(threads=2, job_size=1048576, overlap_log=6)
self.assertEqual(p.threads, 2)
self.assertEqual(p.job_size, 1048576)
self.assertEqual(p.overlap_log, 6)
self.assertEqual(p.overlap_size_log, 6)
p = zstd.ZstdCompressionParameters(compression_level=-1)
self.assertEqual(p.compression_level, -1)
p = zstd.ZstdCompressionParameters(compression_level=-2)
self.assertEqual(p.compression_level, -2)
p = zstd.ZstdCompressionParameters(force_max_window=True)
self.assertEqual(p.force_max_window, 1)
p = zstd.ZstdCompressionParameters(enable_ldm=True)
self.assertEqual(p.enable_ldm, 1)
p = zstd.ZstdCompressionParameters(ldm_hash_log=7)
self.assertEqual(p.ldm_hash_log, 7)
p = zstd.ZstdCompressionParameters(ldm_min_match=6)
self.assertEqual(p.ldm_min_match, 6)
p = zstd.ZstdCompressionParameters(ldm_bucket_size_log=7)
self.assertEqual(p.ldm_bucket_size_log, 7)
p = zstd.ZstdCompressionParameters(ldm_hash_rate_log=8)
self.assertEqual(p.ldm_hash_every_log, 8)
def test_bounds(self):
zstd.ZstdCompressionParameters(
window_log=zstd.WINDOWLOG_MIN,
chain_log=zstd.CHAINLOG_MIN,
hash_log=zstd.HASHLOG_MIN,
search_log=zstd.SEARCHLOG_MIN,
min_match=zstd.MINMATCH_MIN + 1,
target_length=zstd.TARGETLENGTH_MIN,
strategy=zstd.STRATEGY_FAST,
)
zstd.ZstdCompressionParameters(
window_log=zstd.WINDOWLOG_MAX,
chain_log=zstd.CHAINLOG_MAX,
hash_log=zstd.HASHLOG_MAX,
search_log=zstd.SEARCHLOG_MAX,
min_match=zstd.MINMATCH_MAX - 1,
target_length=zstd.TARGETLENGTH_MAX,
self.assertEqual(p.overlap_log, 6)
self.assertEqual(p.overlap_size_log, 6)
p = zstd.ZstdCompressionParameters(compression_level=-1)
self.assertEqual(p.compression_level, -1)
p = zstd.ZstdCompressionParameters(compression_level=-2)
self.assertEqual(p.compression_level, -2)
p = zstd.ZstdCompressionParameters(force_max_window=True)
self.assertEqual(p.force_max_window, 1)
p = zstd.ZstdCompressionParameters(enable_ldm=True)
self.assertEqual(p.enable_ldm, 1)
p = zstd.ZstdCompressionParameters(ldm_hash_log=7)
self.assertEqual(p.ldm_hash_log, 7)
p = zstd.ZstdCompressionParameters(ldm_min_match=6)
self.assertEqual(p.ldm_min_match, 6)
p = zstd.ZstdCompressionParameters(ldm_bucket_size_log=7)
self.assertEqual(p.ldm_bucket_size_log, 7)
p = zstd.ZstdCompressionParameters(ldm_hash_rate_log=8)
self.assertEqual(p.ldm_hash_every_log, 8)
self.assertEqual(p.ldm_hash_rate_log, 8)
)
self.assertEqual(p.window_log, 10)
self.assertEqual(p.chain_log, 6)
self.assertEqual(p.hash_log, 7)
self.assertEqual(p.search_log, 4)
self.assertEqual(p.min_match, 5)
self.assertEqual(p.target_length, 8)
self.assertEqual(p.compression_strategy, 1)
p = zstd.ZstdCompressionParameters(compression_level=2)
self.assertEqual(p.compression_level, 2)
p = zstd.ZstdCompressionParameters(threads=4)
self.assertEqual(p.threads, 4)
p = zstd.ZstdCompressionParameters(threads=2, job_size=1048576, overlap_log=6)
self.assertEqual(p.threads, 2)
self.assertEqual(p.job_size, 1048576)
self.assertEqual(p.overlap_log, 6)
self.assertEqual(p.overlap_size_log, 6)
p = zstd.ZstdCompressionParameters(compression_level=-1)
self.assertEqual(p.compression_level, -1)
p = zstd.ZstdCompressionParameters(compression_level=-2)
self.assertEqual(p.compression_level, -2)
p = zstd.ZstdCompressionParameters(force_max_window=True)
self.assertEqual(p.force_max_window, 1)
p = zstd.ZstdCompressionParameters(enable_ldm=True)
self.assertEqual(p.enable_ldm, 1)
min_match=5,
target_length=8,
strategy=1,
)
self.assertEqual(p.window_log, 10)
self.assertEqual(p.chain_log, 6)
self.assertEqual(p.hash_log, 7)
self.assertEqual(p.search_log, 4)
self.assertEqual(p.min_match, 5)
self.assertEqual(p.target_length, 8)
self.assertEqual(p.compression_strategy, 1)
p = zstd.ZstdCompressionParameters(compression_level=2)
self.assertEqual(p.compression_level, 2)
p = zstd.ZstdCompressionParameters(threads=4)
self.assertEqual(p.threads, 4)
p = zstd.ZstdCompressionParameters(threads=2, job_size=1048576, overlap_log=6)
self.assertEqual(p.threads, 2)
self.assertEqual(p.job_size, 1048576)
self.assertEqual(p.overlap_log, 6)
self.assertEqual(p.overlap_size_log, 6)
p = zstd.ZstdCompressionParameters(compression_level=-1)
self.assertEqual(p.compression_level, -1)
p = zstd.ZstdCompressionParameters(compression_level=-2)
self.assertEqual(p.compression_level, -2)
p = zstd.ZstdCompressionParameters(force_max_window=True)
self.assertEqual(p.force_max_window, 1)
def test_ldm_hash_rate_log(self):
with self.assertRaisesRegex(
ValueError, "cannot specify both ldm_hash_rate_log"
):
zstd.ZstdCompressionParameters(ldm_hash_rate_log=8, ldm_hash_every_log=4)
p = zstd.ZstdCompressionParameters(ldm_hash_rate_log=8)
self.assertEqual(p.ldm_hash_every_log, 8)
p = zstd.ZstdCompressionParameters(ldm_hash_every_log=16)
self.assertEqual(p.ldm_hash_every_log, 16)
def compress_data_zstandard(data):
""" Compress data via zstandard
"""
import zstandard as zstd
params = zstd.ZstdCompressionParameters(
window_log=12
)
cctx = zstd.ZstdCompressor(level=22, compression_params=params)
compressed_data = cctx.compress(data, )
return compressed_data