本文整理匯總了Python中lzma.FILTER_LZMA1屬性的典型用法代碼示例。如果您正苦於以下問題:Python lzma.FILTER_LZMA1屬性的具體用法?Python lzma.FILTER_LZMA1怎麽用?Python lzma.FILTER_LZMA1使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類lzma
的用法示例。
在下文中一共展示了lzma.FILTER_LZMA1屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: decompress
# 需要導入模塊: import lzma [as 別名]
# 或者: from lzma import FILTER_LZMA1 [as 別名]
def decompress(self, buf):
if not self.compressed:
return buf
ty = self.compression_type
if ty == CompressionType.LZMA:
props, dict_size = struct.unpack("<BI", buf.read(5))
lc = props % 9
props = int(props / 9)
pb = int(props / 5)
lp = props % 5
dec = lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=[{
"id": lzma.FILTER_LZMA1,
"dict_size": dict_size,
"lc": lc,
"lp": lp,
"pb": pb,
}])
res = dec.decompress(buf.read())
return BytesIO(res)
if ty in (CompressionType.LZ4, CompressionType.LZ4HC):
res = lz4_decompress(buf.read(self.compressed_size), self.uncompressed_size)
return BytesIO(res)
raise NotImplementedError("Unimplemented compression method: %r" % (ty))
示例2: get_coder
# 需要導入模塊: import lzma [as 別名]
# 或者: from lzma import FILTER_LZMA1 [as 別名]
def get_coder(cls, filter) -> Dict[str, Any]:
method = cls.get_method_id(filter)
if filter['id'] in [lzma.FILTER_LZMA1, lzma.FILTER_LZMA2, lzma.FILTER_DELTA]:
properties = lzma._encode_filter_properties(filter) # type: Optional[bytes] # type: ignore # noqa
else:
properties = None
return {'method': method, 'properties': properties, 'numinstreams': 1, 'numoutstreams': 1}
示例3: test_lzmadecompressor_lzmabcj
# 需要導入模塊: import lzma [as 別名]
# 或者: from lzma import FILTER_LZMA1 [as 別名]
def test_lzmadecompressor_lzmabcj():
indata = b'This file is located in the root.'
compressor = lzma.LZMACompressor(format=lzma.FORMAT_RAW,
filters=[{'id': lzma.FILTER_X86}, {'id': lzma.FILTER_LZMA1}])
compressed = compressor.compress(indata)
compressed += compressor.flush()
decompressor = lzma.LZMADecompressor(format=lzma.FORMAT_RAW,
filters=[{'id': lzma.FILTER_X86}, {'id': lzma.FILTER_LZMA1}])
outdata = decompressor.decompress(data=compressed)
assert outdata == indata
示例4: __init__
# 需要導入模塊: import lzma [as 別名]
# 或者: from lzma import FILTER_LZMA1 [as 別名]
def __init__(self, preset=None, compress_options=None):
super().__init__()
if compress_options is None:
compress_options = {}
if (compress_options.setdefault("id", lzma.FILTER_LZMA1)
!= lzma.FILTER_LZMA1
):
raise ValueError(
"Illegal LZMA filter ID: " + repr(compress_options["id"]))
if preset is not None:
compress_options["preset"] = preset
self.compress_options = compress_options
示例5: encode_file
# 需要導入模塊: import lzma [as 別名]
# 或者: from lzma import FILTER_LZMA1 [as 別名]
def encode_file(path, max_len=4):
basename = os.path.splitext(path)[0]
encodedname = basename + ".encoded.csv"
print("process:", path, "->", encodedname)
with open(path, 'rb') as f:
data = f.read()
filters = [
{
"id": lzma.FILTER_LZMA1,
"dict_size": 256 * 1024,
"lc": 3,
"lp": 0,
"pb": 2,
"mode": lzma.MODE_NORMAL
},
]
pack_data = lzma.compress(data, format=lzma.FORMAT_ALONE, filters=filters)
lzmadata = bytearray()
for i in range(0, 5):
lzmadata.append(pack_data[i])
data_size = len_2_bytes(len(data), max_len)
for size in data_size:
lzmadata.append(size)
for i in range(13, len(pack_data)):
lzmadata.append(pack_data[i])
#for i in range(0, len(lzmadata)):
# print("i: ", i, " val: ", lzmadata[i])
with open(encodedname, 'wb') as f:
f.write(lzmadata)
#
# restore_file
#