本文整理汇总了Python中mozpack.mozjar.Deflater.write方法的典型用法代码示例。如果您正苦于以下问题:Python Deflater.write方法的具体用法?Python Deflater.write怎么用?Python Deflater.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozpack.mozjar.Deflater
的用法示例。
在下文中一共展示了Deflater.write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DeflaterDest
# 需要导入模块: from mozpack.mozjar import Deflater [as 别名]
# 或者: from mozpack.mozjar.Deflater import write [as 别名]
class DeflaterDest(Dest):
'''
Dest-like class, reading from a file-like object initially, but
switching to a Deflater object if written to.
dest = DeflaterDest(original_file)
dest.read() # Reads original_file
dest.write(data) # Creates a Deflater and write data there
dest.read() # Re-opens the Deflater and reads from it
'''
def __init__(self, orig=None, compress=True):
self.mode = None
self.deflater = orig
self.compress = compress
def read(self, length=-1):
if self.mode != 'r':
assert self.mode is None
self.mode = 'r'
return self.deflater.read(length)
def write(self, data):
if self.mode != 'w':
from mozpack.mozjar import Deflater
self.deflater = Deflater(self.compress)
self.mode = 'w'
self.deflater.write(data)
def exists(self):
return self.deflater is not None
示例2: test_deflater_compress_no_gain
# 需要导入模块: from mozpack.mozjar import Deflater [as 别名]
# 或者: from mozpack.mozjar.Deflater import write [as 别名]
def test_deflater_compress_no_gain(self):
deflater = Deflater(True)
deflater.write(self.wrap('abc'))
self.assertFalse(deflater.compressed)
self.assertEqual(deflater.uncompressed_size, 3)
self.assertEqual(deflater.compressed_size, deflater.uncompressed_size)
self.assertEqual(deflater.compressed_data, 'abc')
self.assertEqual(deflater.crc32, 0x352441c2)
示例3: test_deflater_compress
# 需要导入模块: from mozpack.mozjar import Deflater [as 别名]
# 或者: from mozpack.mozjar.Deflater import write [as 别名]
def test_deflater_compress(self):
deflater = Deflater(True)
deflater.write(self.wrap('aaaaaaaaaaaaanopqrstuvwxyz'))
self.assertTrue(deflater.compressed)
self.assertEqual(deflater.uncompressed_size, 26)
self.assertNotEqual(deflater.compressed_size,
deflater.uncompressed_size)
self.assertEqual(deflater.crc32, 0xd46b97ed)
# The CRC is the same as when not compressed
deflater = Deflater(False)
self.assertFalse(deflater.compressed)
deflater.write(self.wrap('aaaaaaaaaaaaanopqrstuvwxyz'))
self.assertEqual(deflater.crc32, 0xd46b97ed)