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


Python BZ2Compressor.compress方法代码示例

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


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

示例1: testCompress

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testCompress(self):
        # "Test BZ2Compressor.compress()/flush()"
        bz2c = BZ2Compressor()
        self.assertRaises(TypeError, bz2c.compress)
        data = bz2c.compress(self.TEXT)
        data += bz2c.flush()
        self.assertEqual(self.decompress(data), self.TEXT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_bz2.py

示例2: testCompressEmptyString

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testCompressEmptyString(self):
        # "Test BZ2Compressor.compress()/flush() of empty string"
        bz2c = BZ2Compressor()
        data = bz2c.compress('')
        data += bz2c.flush()
        self.assertEqual(data, self.EMPTY_DATA) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:test_bz2.py

示例3: testCompressChunks10

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testCompressChunks10(self):
        # "Test BZ2Compressor.compress()/flush() with chunks of 10 bytes"
        bz2c = BZ2Compressor()
        n = 0
        data = ''
        while 1:
            str = self.TEXT[n*10:(n+1)*10]
            if not str:
                break
            data += bz2c.compress(str)
            n += 1
        data += bz2c.flush()
        self.assertEqual(self.decompress(data), self.TEXT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:15,代码来源:test_bz2.py

示例4: testBigmem

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testBigmem(self, size):
        text = "a" * size
        bz2c = bz2.BZ2Compressor()
        data = bz2c.compress(text) + bz2c.flush()
        del text
        text = self.decompress(data)
        self.assertEqual(len(text), size)
        self.assertEqual(text.strip("a"), "") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_bz2.py

示例5: testCompressBigmem

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testCompressBigmem(self, size):
        text = "a" * size
        data = bz2.compress(text)
        del text
        text = self.decompress(data)
        self.assertEqual(len(text), size)
        self.assertEqual(text.strip("a"), "") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_bz2.py

示例6: testDecompressBigmem

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testDecompressBigmem(self, size):
        # Issue #14398: decompression fails when output data is >=2GB.
        if size < _4G:
            self.skipTest("Test needs 5GB of memory to run.")
        compressed = bz2.compress("a" * _4G)
        text = bz2.decompress(compressed)
        self.assertEqual(len(text), _4G)
        self.assertEqual(text.strip("a"), "") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_bz2.py

示例7: testWriteNonDefaultCompressLevel

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testWriteNonDefaultCompressLevel(self):
        expected = bz2.compress(self.TEXT, compresslevel=5)
        with BZ2File(self.filename, "w", compresslevel=5) as bz2f:
            bz2f.write(self.TEXT)
        with open(self.filename, "rb") as f:
            self.assertEqual(f.read(), expected) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_bz2.py

示例8: testDecompressLimited

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testDecompressLimited(self):
        """Decompressed data buffering should be limited"""
        bomb = bz2.compress(bytes(int(2e6)), compresslevel=9)
        self.assertLess(len(bomb), _compression.BUFFER_SIZE)

        decomp = BZ2File(BytesIO(bomb))
        self.assertEqual(bytes(1), decomp.read(1))
        max_decomp = 1 + DEFAULT_BUFFER_SIZE
        self.assertLessEqual(decomp._buffer.raw.tell(), max_decomp,
            "Excessive amount of data was decompressed")


    # Tests for a BZ2File wrapping another file object: 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_bz2.py

示例9: testCompress

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testCompress(self):
        bz2c = BZ2Compressor()
        self.assertRaises(TypeError, bz2c.compress)
        data = bz2c.compress(self.TEXT)
        data += bz2c.flush()
        self.assertEqual(self.decompress(data), self.TEXT) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_bz2.py

示例10: testCompressEmptyString

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testCompressEmptyString(self):
        bz2c = BZ2Compressor()
        data = bz2c.compress(b'')
        data += bz2c.flush()
        self.assertEqual(data, self.EMPTY_DATA) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_bz2.py

示例11: testCompressChunks10

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testCompressChunks10(self):
        bz2c = BZ2Compressor()
        n = 0
        data = b''
        while True:
            str = self.TEXT[n*10:(n+1)*10]
            if not str:
                break
            data += bz2c.compress(str)
            n += 1
        data += bz2c.flush()
        self.assertEqual(self.decompress(data), self.TEXT) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_bz2.py

示例12: testDecompress4G

# 需要导入模块: from bz2 import BZ2Compressor [as 别名]
# 或者: from bz2.BZ2Compressor import compress [as 别名]
def testDecompress4G(self, size):
        # "Test BZ2Decompressor.decompress() with >4GiB input"
        blocksize = 10 * 1024 * 1024
        block = random.getrandbits(blocksize * 8).to_bytes(blocksize, 'little')
        try:
            data = block * (size // blocksize + 1)
            compressed = bz2.compress(data)
            bz2d = BZ2Decompressor()
            decompressed = bz2d.decompress(compressed)
            self.assertTrue(decompressed == data)
        finally:
            data = None
            compressed = None
            decompressed = None 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:16,代码来源:test_bz2.py


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