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


Python mozjar.Deflater類代碼示例

本文整理匯總了Python中mozpack.mozjar.Deflater的典型用法代碼示例。如果您正苦於以下問題:Python Deflater類的具體用法?Python Deflater怎麽用?Python Deflater使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Deflater類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: DeflaterDest

        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,代碼行數:30,代碼來源:copier.py

示例2: test_deflater_compress_no_gain

 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,代碼行數:8,代碼來源:test_mozjar.py

示例3: write

            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)
開發者ID:hibrium,項目名稱:Pale-Moon,代碼行數:7,代碼來源:copier.py

示例4: test_deflater_compress

 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,代碼行數:13,代碼來源:test_mozjar.py


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