/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tuned_gzip.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Legacy breezy specific gzip tunings."""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
import struct
21
23
import zlib
22
24
 
23
 
__all__ = ["chunks_to_gzip"]
 
25
__all__ = ["bytes_to_gzip", "chunks_to_gzip"]
24
26
 
25
27
 
26
28
def U32(i):
38
40
    return i & 0xFFFFFFFF
39
41
 
40
42
 
 
43
def bytes_to_gzip(bytes, factory=zlib.compressobj,
 
44
    level=zlib.Z_DEFAULT_COMPRESSION, method=zlib.DEFLATED,
 
45
    width=-zlib.MAX_WBITS, mem=zlib.DEF_MEM_LEVEL,
 
46
    crc32=zlib.crc32):
 
47
    """Create a gzip file containing bytes and return its content."""
 
48
    return chunks_to_gzip([bytes])
 
49
 
 
50
 
41
51
def chunks_to_gzip(chunks, factory=zlib.compressobj,
42
 
                   level=zlib.Z_DEFAULT_COMPRESSION, method=zlib.DEFLATED,
43
 
                   width=-zlib.MAX_WBITS, mem=zlib.DEF_MEM_LEVEL,
44
 
                   crc32=zlib.crc32):
 
52
    level=zlib.Z_DEFAULT_COMPRESSION, method=zlib.DEFLATED,
 
53
    width=-zlib.MAX_WBITS, mem=zlib.DEF_MEM_LEVEL,
 
54
    crc32=zlib.crc32):
45
55
    """Create a gzip file containing chunks and return its content.
46
56
 
47
57
    :param chunks: An iterable of strings. Each string can have arbitrary
59
69
        b'\002'      # self.fileobj.write('\002')
60
70
        b'\377'      # self.fileobj.write('\377')
61
71
                     # if fname:
62
 
        b''  # self.fileobj.write(fname + '\000')
 
72
        b''          #     self.fileobj.write(fname + '\000')
63
73
        ]
64
74
    # using a compressobj avoids a small header and trailer that the compress()
65
75
    # utility function adds.
75
85
    result.append(compress.flush())
76
86
    # size may exceed 2GB, or even 4GB
77
87
    result.append(struct.pack("<LL", LOWU32(crc), LOWU32(total_len)))
78
 
    return result
 
88
    return b''.join(result)