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


Python lzma.compress方法代码示例

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


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

示例1: CompressBrotli

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

    """
    compressed = brotli.compress(string.encode("ascii"))
    number = 1
    for c in compressed:
        number = number * 256 + c
    result = ""
    while number:
        result = Codepage[number % 255] + result
        number //= 255
    return Codepage[BROTLI_ENCODING] + result 
开发者ID:somebody1234,项目名称:Charcoal,代码行数:18,代码来源:compression.py

示例2: CompressLZMA

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [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

示例3: run

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def run(results, raw_paste_data, paste_object):
    if config['outputs']['json_output']['store_raw']:
        original = raw_paste_data
        orig_size = len(original.encode())
        logger.debug("Compressing paste... Pre-compression size: {}", orig_size)
        compressed = base64.b64encode(lzma.compress(raw_paste_data.encode()))
        compressed_size = len(compressed)
        logger.debug("Compressing paste... Post-compression size: {}", compressed_size)

        # In some cases compressed blobs may be larger
        # if not much data is compressed
        if orig_size > compressed_size:
            paste_object['raw_paste'] = compressed.decode('utf-8')
            logger.debug("Compressed data smaller than original blob. Keeping compressed.")
        else:
            logger.debug("Original smaller than compressed blob. Keeping original.")

    # Regardless of modification, return the paste object
    return paste_object 
开发者ID:kevthehermit,项目名称:PasteHunter,代码行数:21,代码来源:post_compress.py

示例4: test_decompression_event

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def test_decompression_event(self):
        ifile = WALTester(self.incoming_path, "00000001000000000000000A", "random")
        callback_queue = Queue()
        local_filepath = os.path.join(self.temp_dir, "00000001000000000000000A")
        self.compression_queue.put({
            "blob": self.compress(ifile.contents),
            "callback_queue": callback_queue,
            "filetype": "xlog",
            "local_path": local_filepath,
            "metadata": {
                "compression-algorithm": self.algorithm,
                "compression-level": 0,
                "host": socket.gethostname(),
                "original-file-size": ifile.size,
                "pg-version": 90500,
            },
            "site": self.test_site,
            "type": "DECOMPRESSION",
        })
        callback_queue.get(timeout=5.0)
        assert os.path.exists(local_filepath) is True
        with open(local_filepath, "rb") as fp:
            fdata = fp.read()
        assert fdata[:100] == ifile.contents[:100]
        assert fdata == ifile.contents 
开发者ID:aiven,项目名称:pghoard,代码行数:27,代码来源:test_compressor.py

示例5: test_snappy_read

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def test_snappy_read(self, tmpdir):
        comp = snappy.StreamCompressor()
        # generate two chunks with their own framing
        compressed = comp.compress(b"hello, ") + comp.compress(b"world")
        file_path = tmpdir.join("foo").strpath
        with open(file_path, "wb") as fp:
            fp.write(compressed)

        out = []
        with SnappyFile(open(file_path, "rb"), "rb") as fp:
            while True:
                chunk = fp.read()
                if not chunk:
                    break
                out.append(chunk)

        full = b"".join(out)
        assert full == b"hello, world" 
开发者ID:aiven,项目名称:pghoard,代码行数:20,代码来源:test_compressor.py

示例6: bz2_pack

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def bz2_pack(source):
    """
    Returns `source` as bzip2-compressed Python script
    """
    import bz2
    compressed = base64.b64encode(bz2.compress(
        source.encode('utf-8'))).decode('utf-8')
    return f'import bz2,base64;exec(bz2.decompress(base64.b64decode("{compressed}")))' 
开发者ID:PyObfx,项目名称:PyObfx,代码行数:10,代码来源:packer.py

示例7: gz_pack

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def gz_pack(source):
    """
    Returns `source` as gzip-compressed Python script
    """
    import zlib
    compressed = base64.b64encode(zlib.compress(source.encode('utf-8'))).decode('utf-8')
    return f'import zlib,base64;exec(zlib.decompress(base64.b64decode("{compressed}")))' 
开发者ID:PyObfx,项目名称:PyObfx,代码行数:9,代码来源:packer.py

示例8: lzma_pack

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def lzma_pack(source):
    """
    Returns `source` as lzma-compressed Python script
    """
    import lzma
    compressed = base64.b64encode(lzma.compress(source.encode('utf-8'))).decode('utf-8')
    return f'import lzma,base64;exec(lzma.decompress(base64.b64decode("{compressed}")))' 
开发者ID:PyObfx,项目名称:PyObfx,代码行数:9,代码来源:packer.py

示例9: test_index_gzip

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def test_index_gzip(self, urlopen_mock):
    if not Compression.GZIP.available:
      self.skipTest('(gzip compression unavailable)')

    import zlib
    urlopen_mock.return_value = io.BytesIO(zlib.compress(EXAMPLE_INDEX_JSON))

    collector = CollecTor()
    self.assertEqual(EXAMPLE_INDEX, collector.index(Compression.GZIP))
    urlopen_mock.assert_called_with('https://collector.torproject.org/index/index.json.gz', timeout = None) 
开发者ID:torproject,项目名称:stem,代码行数:12,代码来源:collector.py

示例10: test_index_bz2

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def test_index_bz2(self, urlopen_mock):
    if not Compression.BZ2.available:
      self.skipTest('(bz2 compression unavailable)')

    import bz2
    urlopen_mock.return_value = io.BytesIO(bz2.compress(EXAMPLE_INDEX_JSON))

    collector = CollecTor()
    self.assertEqual(EXAMPLE_INDEX, collector.index(Compression.BZ2))
    urlopen_mock.assert_called_with('https://collector.torproject.org/index/index.json.bz2', timeout = None) 
开发者ID:torproject,项目名称:stem,代码行数:12,代码来源:collector.py

示例11: test_index_lzma

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def test_index_lzma(self, urlopen_mock):
    if not Compression.LZMA.available:
      self.skipTest('(lzma compression unavailable)')

    import lzma
    urlopen_mock.return_value = io.BytesIO(lzma.compress(EXAMPLE_INDEX_JSON))

    collector = CollecTor()
    self.assertEqual(EXAMPLE_INDEX, collector.index(Compression.LZMA))
    urlopen_mock.assert_called_with('https://collector.torproject.org/index/index.json.xz', timeout = None) 
开发者ID:torproject,项目名称:stem,代码行数:12,代码来源:collector.py

示例12: encode

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def encode(self, buf):

            # normalise inputs
            buf = ensure_contiguous_ndarray(buf)

            # do compression
            return _lzma.compress(buf, format=self.format, check=self.check,
                                  preset=self.preset, filters=self.filters) 
开发者ID:zarr-developers,项目名称:numcodecs,代码行数:10,代码来源:lzma.py

示例13: _compress

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def _compress(self, data):
        if not lzma:
            raise ImportError('Please, install the PylibLZMA module')
        return lzma.compress(data)[14:] 
开发者ID:life4,项目名称:textdistance,代码行数:6,代码来源:compression_based.py

示例14: _compression_dist

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def _compression_dist(x, y, l_x=None, l_y=None):
    if x == y:
        return 0
    x_b = x.encode('utf-8')
    y_b = y.encode('utf-8')
    if l_x is None:
        l_x = len(lzma.compress(x_b))
        l_y = len(lzma.compress(y_b))
    l_xy = len(lzma.compress(x_b+y_b))
    l_yx = len(lzma.compress(y_b+x_b))
    dist = np_utils._try_divide(min(l_xy,l_yx)-min(l_x,l_y), max(l_x,l_y))
    return dist 
开发者ID:ChenglongChen,项目名称:kaggle-HomeDepot,代码行数:14,代码来源:dist_utils.py

示例15: format_compress_string

# 需要导入模块: import lzma [as 别名]
# 或者: from lzma import compress [as 别名]
def format_compress_string(data, base, compress, width, encode):
    return format_compress(data, base, compress, width, encode, is_file=False) 
开发者ID:cilame,项目名称:vrequest,代码行数:4,代码来源:pycompress.py


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