Python lzma.FILTER_LZMA1 Examples
The following are 5
code examples of lzma.FILTER_LZMA1().
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: assetbundle.py From UnityPack with MIT License | 6 votes |
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))
Example #2
Source File: compressor.py From py7zr with GNU Lesser General Public License v2.1 | 5 votes |
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}
Example #3
Source File: test_unit.py From py7zr with GNU Lesser General Public License v2.1 | 5 votes |
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
Example #4
Source File: zip.py From aptsources-cleanup with MIT License | 5 votes |
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
Example #5
Source File: lib_csv.py From supercell_resource_decoder with MIT License | 4 votes |
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 #