[issue5804] Add an 'offset' argument to zlib.decompress - Code Review (original) (raw)

OLD

NEW

1

1

2 :mod:`zlib` --- Compression compatible with :program:`gzip`

2 :mod:`zlib` --- Compression compatible with :program:`gzip`

3 ===========================================================

3 ===========================================================

4

4

5 .. module:: zlib

5 .. module:: zlib

6 :synopsis: Low-level interface to compression and decompression routines comp atible with

6 :synopsis: Low-level interface to compression and decompression routines comp atible with

7 gzip.

7 gzip.

8

8

9

9

10 For applications that require data compression, the functions in this module

10 For applications that require data compression, the functions in this module

(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...

104 .. versionchanged:: 2.6

104 .. versionchanged:: 2.6

105 The return value is in the range [-2**31, 2**31-1]

105 The return value is in the range [-2**31, 2**31-1]

106 regardless of platform. In older versions the value would be

106 regardless of platform. In older versions the value would be

107 signed on some platforms and unsigned on others.

107 signed on some platforms and unsigned on others.

108

108

109 .. versionchanged:: 3.0

109 .. versionchanged:: 3.0

110 The return value is unsigned and in the range [0, 2**32-1]

110 The return value is unsigned and in the range [0, 2**32-1]

111 regardless of platform.

111 regardless of platform.

112

112

113

113

114 .. function:: decompress(string[, wbits[, bufsize]])

114 .. function:: decompress(string[, wbits[, bufsize[, offset]]])

115

115

116 Decompresses the data in *string*, returning a string containing the

116 Decompresses the data in *string*, returning a string containing the

117 uncompressed data. The *wbits* parameter controls the size of the window

117 uncompressed data. The *wbits* parameter controls the size of the window

118 buffer. If *bufsize* is given, it is used as the initial size of the output

118 buffer. If *bufsize* is given, it is used as the initial size of the output

119 buffer. Raises the :exc:`error` exception if any error occurs.

119 buffer. Raises the :exc:`error` exception if any error occurs.

120

120

121 The absolute value of *wbits* is the base two logarithm of the size of the

121 The absolute value of *wbits* is the base two logarithm of the size of the

122 history buffer (the "window size") used when compressing data. Its absolute

122 history buffer (the "window size") used when compressing data. Its absolute

123 value should be between 8 and 15 for the most recent versions of the zlib

123 value should be between 8 and 15 for the most recent versions of the zlib

124 library, larger values resulting in better compression at the expense of grea ter

124 library, larger values resulting in better compression at the expense of grea ter

125 memory usage. The default value is 15. When *wbits* is negative, the standa rd

125 memory usage. The default value is 15. When *wbits* is negative, the standa rd

126 :program:`gzip` header is suppressed; this is an undocumented feature of the

126 :program:`gzip` header is suppressed; this is an undocumented feature of the

127 zlib library, used for compatibility with :program:`unzip`'s compression file

127 zlib library, used for compatibility with :program:`unzip`'s compression file

128 format.

128 format.

129

129

130 *bufsize* is the initial size of the buffer used to hold decompressed data. If

130 *bufsize* is the initial size of the buffer used to hold decompressed data. If

131 more space is required, the buffer size will be increased as needed, so you

131 more space is required, the buffer size will be increased as needed, so you

132 don't have to get this value exactly right; tuning it will only save a few ca lls

132 don't have to get this value exactly right; tuning it will only save a few ca lls

133 to :cfunc:`malloc`. The default size is 16384.

133 to :cfunc:`malloc`. The default size is 16384.

134

134

135 *offset* is the initial position in *string* to start decompression.

136 When specified, it will cause the function's return value to be a (uncompress ed, offset)

137 tuple, with the second part giving the position in the input string just afte r

138 any compressed data. This is useful if *string* contains additional data aft er

139 any initial compressed part.

140

141 .. versionchanged:: 2.7

142 Added the *offset* argument

143

135

144

136 .. function:: decompressobj([wbits])

145 .. function:: decompressobj([wbits])

137

146

138 Returns a decompression object, to be used for decompressing data streams tha t

147 Returns a decompression object, to be used for decompressing data streams tha t

139 won't fit into memory at once. The *wbits* parameter controls the size of th e

148 won't fit into memory at once. The *wbits* parameter controls the size of th e

140 window buffer.

149 window buffer.

141

150

142 Compression objects support the following methods:

151 Compression objects support the following methods:

143

152

144

153

(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...

238 Module :mod:`gzip`

247 Module :mod:`gzip`

239 Reading and writing :program:`gzip`\ -format files.

248 Reading and writing :program:`gzip`\ -format files.

240

249

241 http://www.zlib.net

250 http://www.zlib.net

242 The zlib library home page.

251 The zlib library home page.

243

252

244 http://www.zlib.net/manual.html

253 http://www.zlib.net/manual.html

245 The zlib manual explains the semantics and usage of the library's many

254 The zlib manual explains the semantics and usage of the library's many

246 functions.

255 functions.

247

256

OLD

NEW