本文整理汇总了Python中lzma._decode_filter_properties方法的典型用法代码示例。如果您正苦于以下问题:Python lzma._decode_filter_properties方法的具体用法?Python lzma._decode_filter_properties怎么用?Python lzma._decode_filter_properties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lzma
的用法示例。
在下文中一共展示了lzma._decode_filter_properties方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _lzma
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import _decode_filter_properties [as 别名]
def _lzma(f, size):
import lzma
data = f.read()
props = lzma._decode_filter_properties(lzma.FILTER_LZMA1, data[0:5])
return lzma.decompress(data[5:], lzma.FORMAT_RAW, filters=[props])
示例2: get_chunk
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import _decode_filter_properties [as 别名]
def get_chunk(self, app_id, depot_id, chunk_id):
"""Download a single content chunk
:param app_id: App ID
:type app_id: int
:param depot_id: Depot ID
:type depot_id: int
:param chunk_id: Chunk ID
:type chunk_id: int
:returns: chunk data
:rtype: bytes
:raises SteamError: error message
"""
if (depot_id, chunk_id) not in self._chunk_cache:
resp = self.cdn_cmd('depot', '%s/chunk/%s' % (depot_id, chunk_id))
data = symmetric_decrypt(resp.content, self.get_depot_key(app_id, depot_id))
if data[:2] == b'VZ':
if data[-2:] != b'zv':
raise SteamError("VZ: Invalid footer: %s" % repr(data[-2:]))
if data[2:3] != b'a':
raise SteamError("VZ: Invalid version: %s" % repr(data[2:3]))
vzfilter = lzma._decode_filter_properties(lzma.FILTER_LZMA1, data[7:12])
vzdec = lzma.LZMADecompressor(lzma.FORMAT_RAW, filters=[vzfilter])
checksum, decompressed_size = struct.unpack('<II', data[-10:-2])
# decompress_size is needed since lzma will sometime produce longer output
# [12:-9] is need as sometimes lzma will produce shorter output
# together they get us the right data
data = vzdec.decompress(data[12:-9])[:decompressed_size]
if crc32(data) != checksum:
raise SteamError("VZ: CRC32 checksum doesn't match for decompressed data")
else:
with ZipFile(BytesIO(data)) as zf:
data = zf.read(zf.filelist[0])
self._chunk_cache[(depot_id, chunk_id)] = data
return self._chunk_cache[(depot_id, chunk_id)]
示例3: get_lzma_decompressor
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import _decode_filter_properties [as 别名]
def get_lzma_decompressor(coders: List[Dict[str, Any]]):
filters = [] # type: List[Dict[str, Any]]
for coder in coders:
if coder['numinstreams'] != 1 or coder['numoutstreams'] != 1:
raise UnsupportedCompressionMethodError('Only a simple compression method is currently supported.')
if not SupportedMethods.is_native_coder(coder):
raise UnsupportedCompressionMethodError
properties = coder.get('properties', None)
filter_id = SupportedMethods.get_filter_id(coder)
if properties is not None:
filters[:0] = [lzma._decode_filter_properties(filter_id, properties)] # type: ignore
else:
filters[:0] = [{'id': filter_id}]
return lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=filters)
示例4: test_lzma_raw_decompressor_lzmabcj
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import _decode_filter_properties [as 别名]
def test_lzma_raw_decompressor_lzmabcj():
# two files are compress same source by different methods
indata = []
with testdata_path.joinpath('lzma_bcj_1.7z').open('rb') as rawin:
rawin.seek(32)
indata.append(rawin.read(11327))
with testdata_path.joinpath('lzma_bcj_2.7z').open('rb') as rawin:
rawin.seek(32)
indata.append(rawin.read(11334))
filters1 = []
filters1.append({'id': lzma.FILTER_X86})
filters1.append(lzma._decode_filter_properties(lzma.FILTER_LZMA1, b']\x00\x00\x01\x00'))
filters2 = []
filters2.append({'id': lzma.FILTER_X86})
filters2.append(lzma._decode_filter_properties(lzma.FILTER_LZMA2, b'\x0b'))
decompressor1 = lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=filters1)
lzmabcj_out = decompressor1.decompress(indata[0])
decompressor3 = lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=filters2)
lzma2bcj_out = decompressor3.decompress(indata[1])
decompressor4 = lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=filters1[1:])
lzma_out = decompressor4.decompress(indata[0])
decompressor5 = lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=filters2[1:])
lzma2_out = decompressor5.decompress(indata[1])
#
# filters1 pipeline: indata[0] --> LZMA1 --> FILTER_X86 --> lzmabcj_out
# +----> lzma_out
# filters2 pipeline: indata[1] --> LZMA2 --> FILTER_X86 --> lzma2bcj_out
# +----> lzma2_out
#
# lzma_out and lzma2_out are same.
#
# lzmabcj_out and lzma2bcj_out should be same
# but lzmabcj_out lacks last 4 bytes by python lzma/liblzma bug.
#
uncompress_size = 12800
assert lzma_out == lzma2_out
assert len(lzma2bcj_out) == uncompress_size
assert len(lzmabcj_out) == uncompress_size
示例5: process_chunk
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import _decode_filter_properties [as 别名]
def process_chunk(chunk, depot_key):
decrypted_chunk = CryptoUtil.symmetric_decrypt(chunk, depot_key)
if decrypted_chunk[:2] == 'VZ':
filter = lzma._decode_filter_properties(lzma.FILTER_LZMA1, decrypted_chunk[7:12])
lzmadec = lzma.LZMADecompressor(lzma.FORMAT_RAW, None, [filter])
return lzmadec.decompress(decrypted_chunk[12:len(decrypted_chunk)-10])
else:
zip_buffer = StringIO.StringIO(decrypted_chunk)
with zipfile.ZipFile(zip_buffer, 'r') as zip:
return zip.read(zip.namelist()[0])
示例6: _init
# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import _decode_filter_properties [as 别名]
def _init(self):
props = lzma._encode_filter_properties(self.compress_options)
self._comp = lzma.LZMACompressor(
lzma.FORMAT_RAW,
filters=(
lzma._decode_filter_properties(self.compress_options["id"], props),))
return struct.pack("<BBH", 9, 4, len(props)) + props