Python lzma._decode_filter_properties() Examples
The following are 6
code examples of lzma._decode_filter_properties().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
lzma
, or try the search function
.
Example #1
Source File: fileform.py From nrs with GNU General Public License v3.0 | 5 votes |
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])
Example #2
Source File: cdn.py From steam with MIT License | 5 votes |
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)]
Example #3
Source File: compressor.py From py7zr with GNU Lesser General Public License v2.1 | 5 votes |
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)
Example #4
Source File: test_extract.py From py7zr with GNU Lesser General Public License v2.1 | 5 votes |
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
Example #5
Source File: cdn_client.py From CSGO-Market-Float-Finder with MIT License | 5 votes |
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])
Example #6
Source File: zip.py From aptsources-cleanup with MIT License | 5 votes |
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