当前位置: 首页>>代码示例>>Python>>正文


Python lzma.FORMAT_RAW属性代码示例

本文整理汇总了Python中lzma.FORMAT_RAW属性的典型用法代码示例。如果您正苦于以下问题:Python lzma.FORMAT_RAW属性的具体用法?Python lzma.FORMAT_RAW怎么用?Python lzma.FORMAT_RAW使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在lzma的用法示例。


在下文中一共展示了lzma.FORMAT_RAW属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CompressLZMA

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [as 别名]
def CompressLZMA(string):
    """
    CompressBrotli(string) -> str
    Returns without delimiters the given string compressed \
using the lzstring compression method.

    """
    compressed = lzma.compress(
        string.encode("ascii"),
        format=lzma.FORMAT_RAW,
        filters=[{'id': lzma.FILTER_LZMA2, 'preset': 9 | lzma.PRESET_EXTREME}]
    )
    number = 1
    for c in compressed:
        number = number * 256 + c
    result = ""
    while number:
        result = Codepage[number % 255] + result
        number //= 255
    return Codepage[LZMA_ENCODING] + result 
开发者ID:somebody1234,项目名称:Charcoal,代码行数:22,代码来源:compression.py

示例2: DecompressLZMA

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [as 别名]
def DecompressLZMA(string):
    """
    DecompressBrotli(string) -> str
    Returns the original form of the given string compressed \
using Google's brotli compression method., passed without delimiters.

    """
    number = 0
    for character in string:
        ordinal = OrdinalLookup.get(character, ord(character))
        number = number * 255 + ordinal - (ordinal > gap)
    compressed = []
    while number > 1:
        compressed = [number % 256] + compressed
        number //= 256
    return lzma.decompress(
        bytes(compressed),
        format=lzma.FORMAT_RAW,
        filters=[{'id': lzma.FILTER_LZMA2, 'preset': 9 | lzma.PRESET_EXTREME}]
    ).decode("ascii") 
开发者ID:somebody1234,项目名称:Charcoal,代码行数:22,代码来源:compression.py

示例3: decompress

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [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)) 
开发者ID:HearthSim,项目名称:UnityPack,代码行数:25,代码来源:assetbundle.py

示例4: _lzma

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [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]) 
开发者ID:isra17,项目名称:nrs,代码行数:7,代码来源:fileform.py

示例5: init_compressions

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [as 别名]
def init_compressions():
    ident = lambda x: x
    compressions = {'': Compression(ident, ident)}
    for name in ('bz2', 'zlib'):
        try:
            m = __import__(name)
        except ImportError:
            warnings.warn('%s is not available' % name)
        else:
            compressions[name] = Compression(
                lambda x: m.compress(x, 9), m.decompress)

    try:
        import lzma
    except ImportError:
        warnings.warn('lzma is not available')
    else:
        filters = [{'id': lzma.FILTER_LZMA2}]
        compress = lambda s: lzma.compress(s,
                                           format=lzma.FORMAT_RAW,
                                           filters=filters)
        decompress = lambda s: lzma.decompress(s,
                                               format=lzma.FORMAT_RAW,
                                               filters=filters)
        compressions['lzma2'] = Compression(compress, decompress)
    return compressions 
开发者ID:itkach,项目名称:slob,代码行数:28,代码来源:slob.py

示例6: write_masks_to_zarr

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [as 别名]
def write_masks_to_zarr(ds_mask, output_path):
    import lzma
    lzma_filters = [dict(id=lzma.FILTER_DELTA, dist=1),
                    dict(id=lzma.FILTER_LZMA2, preset=1)]
    from numcodecs import LZMA
    compressor = LZMA(filters=lzma_filters, format=lzma.FORMAT_RAW)
    encoding = {vname: {'compressor': compressor} for vname in ds_mask.data_vars}
    return ds_mask.to_zarr(output_path, encoding=encoding) 
开发者ID:MITgcm,项目名称:xmitgcm,代码行数:10,代码来源:llcutils.py

示例7: get_lzma_decompressor

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [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) 
开发者ID:miurahr,项目名称:py7zr,代码行数:16,代码来源:compressor.py

示例8: _set_native_compressors_coders

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [as 别名]
def _set_native_compressors_coders(self, filters):
        self.cchain.add_filter(lzma.LZMACompressor(format=lzma.FORMAT_RAW, filters=filters))
        for filter in filters:
            self.coders.insert(0, SupportedMethods.get_coder(filter)) 
开发者ID:miurahr,项目名称:py7zr,代码行数:6,代码来源:compressor.py

示例9: test_lzma_raw_decompressor_lzmabcj

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [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 
开发者ID:miurahr,项目名称:py7zr,代码行数:40,代码来源:test_extract.py

示例10: test_lzma_lzma2_compressor

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [as 别名]
def test_lzma_lzma2_compressor():
    filters = [{'id': 33, 'dict_size': 16777216}]
    assert lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=filters) is not None 
开发者ID:miurahr,项目名称:py7zr,代码行数:5,代码来源:test_unit.py

示例11: test_lzma_lzma2bcj_compressor

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [as 别名]
def test_lzma_lzma2bcj_compressor():
    filters = [{'id': 4}, {'id': 33, 'dict_size': 16777216}]
    assert lzma.LZMADecompressor(format=lzma.FORMAT_RAW, filters=filters) is not None 
开发者ID:miurahr,项目名称:py7zr,代码行数:5,代码来源:test_unit.py

示例12: test_lzmadecompressor_lzmabcj

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [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 
开发者ID:miurahr,项目名称:py7zr,代码行数:12,代码来源:test_unit.py

示例13: _init

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import FORMAT_RAW [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 
开发者ID:davidfoerster,项目名称:aptsources-cleanup,代码行数:9,代码来源:zip.py


注:本文中的lzma.FORMAT_RAW属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。