當前位置: 首頁>>代碼示例>>Python>>正文


Python Deflater.write方法代碼示例

本文整理匯總了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
開發者ID:AtulKumar2,項目名稱:gecko-dev,代碼行數:32,代碼來源:copier.py

示例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)
開發者ID:JuannyWang,項目名稱:gecko-dev,代碼行數:10,代碼來源:test_mozjar.py

示例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)
開發者ID:JuannyWang,項目名稱:gecko-dev,代碼行數:15,代碼來源:test_mozjar.py


注:本文中的mozpack.mozjar.Deflater.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。