equal
deleted
inserted
replaced
60 def compress(text): |
60 def compress(text): |
61 """ generate a possibly-compressed representation of text """ |
61 """ generate a possibly-compressed representation of text """ |
62 if not text: |
62 if not text: |
63 return ("", text) |
63 return ("", text) |
64 l = len(text) |
64 l = len(text) |
|
65 bin = None |
65 if l < 44: |
66 if l < 44: |
66 if text[0] == '\0': |
67 pass |
67 return ("", text) |
|
68 return ('u', text) |
|
69 elif l > 1000000: |
68 elif l > 1000000: |
70 # zlib makes an internal copy, thus doubling memory usage for |
69 # zlib makes an internal copy, thus doubling memory usage for |
71 # large files, so lets do this in pieces |
70 # large files, so lets do this in pieces |
72 z = zlib.compressobj() |
71 z = zlib.compressobj() |
73 p = [] |
72 p = [] |
79 p.append(z.flush()) |
78 p.append(z.flush()) |
80 if sum(map(len, p)) < l: |
79 if sum(map(len, p)) < l: |
81 bin = "".join(p) |
80 bin = "".join(p) |
82 else: |
81 else: |
83 bin = _compress(text) |
82 bin = _compress(text) |
84 if len(bin) > l: |
83 if bin is None or len(bin) > l: |
85 if text[0] == '\0': |
84 if text[0] == '\0': |
86 return ("", text) |
85 return ("", text) |
87 return ('u', text) |
86 return ('u', text) |
88 return ("", bin) |
87 return ("", bin) |
89 |
88 |