blob: fda392a9cde38f169e97f152cb47a7f701623a59 [file] [log] [blame]
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(zlib_compress__doc__,
Serhiy Storchaka95657cd2016-06-25 22:43:05 +03006"compress($module, data, /, level=Z_DEFAULT_COMPRESSION)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -08007"--\n"
8"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +02009"Returns a bytes object containing compressed data.\n"
10"\n"
Martin Panter1fe0d132016-02-10 10:06:36 +000011" data\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020012" Binary data to be compressed.\n"
13" level\n"
Martin Panterb0cb42d2016-02-10 10:45:54 +000014" Compression level, in 0-9 or -1.");
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020015
16#define ZLIB_COMPRESS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070017 {"compress", (PyCFunction)zlib_compress, METH_FASTCALL, zlib_compress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020018
19static PyObject *
Serhiy Storchaka2954f832016-07-07 18:20:03 +030020zlib_compress_impl(PyObject *module, Py_buffer *data, int level);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020021
22static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070023zlib_compress(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020024{
25 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +030026 static const char * const _keywords[] = {"", "level", NULL};
27 static _PyArg_Parser _parser = {"y*|i:compress", _keywords, 0};
Martin Panter1fe0d132016-02-10 10:06:36 +000028 Py_buffer data = {NULL, NULL};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020029 int level = Z_DEFAULT_COMPRESSION;
30
Victor Stinner37e4ef72016-09-09 20:00:13 -070031 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030032 &data, &level)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020033 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030034 }
Martin Panter1fe0d132016-02-10 10:06:36 +000035 return_value = zlib_compress_impl(module, &data, level);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020036
37exit:
Martin Panter1fe0d132016-02-10 10:06:36 +000038 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030039 if (data.obj) {
Martin Panter1fe0d132016-02-10 10:06:36 +000040 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030041 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020042
43 return return_value;
44}
45
46PyDoc_STRVAR(zlib_decompress__doc__,
Serhiy Storchaka15f32282016-08-15 10:06:16 +030047"decompress($module, data, /, wbits=MAX_WBITS, bufsize=DEF_BUF_SIZE)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -080048"--\n"
49"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020050"Returns a bytes object containing the uncompressed data.\n"
51"\n"
52" data\n"
53" Compressed data.\n"
54" wbits\n"
Martin Panter0fdf41d2016-05-27 07:32:11 +000055" The window buffer size and container format.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020056" bufsize\n"
57" The initial output buffer size.");
58
59#define ZLIB_DECOMPRESS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -070060 {"decompress", (PyCFunction)zlib_decompress, METH_FASTCALL, zlib_decompress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020061
62static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030063zlib_decompress_impl(PyObject *module, Py_buffer *data, int wbits,
Martin Panter84544c12016-07-23 03:02:07 +000064 Py_ssize_t bufsize);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020065
66static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -070067zlib_decompress(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020068{
69 PyObject *return_value = NULL;
Serhiy Storchaka15f32282016-08-15 10:06:16 +030070 static const char * const _keywords[] = {"", "wbits", "bufsize", NULL};
71 static _PyArg_Parser _parser = {"y*|iO&:decompress", _keywords, 0};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020072 Py_buffer data = {NULL, NULL};
73 int wbits = MAX_WBITS;
Martin Panter84544c12016-07-23 03:02:07 +000074 Py_ssize_t bufsize = DEF_BUF_SIZE;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020075
Victor Stinner37e4ef72016-09-09 20:00:13 -070076 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Martin Panter525a9492016-07-23 03:39:49 +000077 &data, &wbits, ssize_t_converter, &bufsize)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020078 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030079 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020080 return_value = zlib_decompress_impl(module, &data, wbits, bufsize);
81
82exit:
83 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030084 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020085 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030086 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020087
88 return return_value;
89}
90
91PyDoc_STRVAR(zlib_compressobj__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080092"compressobj($module, /, level=Z_DEFAULT_COMPRESSION, method=DEFLATED,\n"
93" wbits=MAX_WBITS, memLevel=DEF_MEM_LEVEL,\n"
94" strategy=Z_DEFAULT_STRATEGY, zdict=None)\n"
95"--\n"
96"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +020097"Return a compressor object.\n"
98"\n"
99" level\n"
Martin Panter567d5132016-02-03 07:06:33 +0000100" The compression level (an integer in the range 0-9 or -1; default is\n"
101" currently equivalent to 6). Higher compression levels are slower,\n"
102" but produce smaller results.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200103" method\n"
104" The compression algorithm. If given, this must be DEFLATED.\n"
105" wbits\n"
Martin Panter0fdf41d2016-05-27 07:32:11 +0000106" +9 to +15: The base-two logarithm of the window size. Include a zlib\n"
107" container.\n"
108" -9 to -15: Generate a raw stream.\n"
109" +25 to +31: Include a gzip container.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200110" memLevel\n"
111" Controls the amount of memory used for internal compression state.\n"
112" Valid values range from 1 to 9. Higher values result in higher memory\n"
113" usage, faster compression, and smaller output.\n"
114" strategy\n"
115" Used to tune the compression algorithm. Possible values are\n"
116" Z_DEFAULT_STRATEGY, Z_FILTERED, and Z_HUFFMAN_ONLY.\n"
117" zdict\n"
118" The predefined compression dictionary - a sequence of bytes\n"
119" containing subsequences that are likely to occur in the input data.");
120
121#define ZLIB_COMPRESSOBJ_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700122 {"compressobj", (PyCFunction)zlib_compressobj, METH_FASTCALL, zlib_compressobj__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200123
124static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300125zlib_compressobj_impl(PyObject *module, int level, int method, int wbits,
Larry Hastings89964c42015-04-14 18:07:59 -0400126 int memLevel, int strategy, Py_buffer *zdict);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200127
128static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700129zlib_compressobj(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200130{
131 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300132 static const char * const _keywords[] = {"level", "method", "wbits", "memLevel", "strategy", "zdict", NULL};
133 static _PyArg_Parser _parser = {"|iiiiiy*:compressobj", _keywords, 0};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200134 int level = Z_DEFAULT_COMPRESSION;
135 int method = DEFLATED;
136 int wbits = MAX_WBITS;
137 int memLevel = DEF_MEM_LEVEL;
138 int strategy = Z_DEFAULT_STRATEGY;
139 Py_buffer zdict = {NULL, NULL};
140
Victor Stinner37e4ef72016-09-09 20:00:13 -0700141 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300142 &level, &method, &wbits, &memLevel, &strategy, &zdict)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200143 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300144 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200145 return_value = zlib_compressobj_impl(module, level, method, wbits, memLevel, strategy, &zdict);
146
147exit:
148 /* Cleanup for zdict */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300149 if (zdict.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200150 PyBuffer_Release(&zdict);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300151 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200152
153 return return_value;
154}
155
156PyDoc_STRVAR(zlib_decompressobj__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800157"decompressobj($module, /, wbits=MAX_WBITS, zdict=b\'\')\n"
158"--\n"
159"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200160"Return a decompressor object.\n"
161"\n"
162" wbits\n"
Martin Panter0fdf41d2016-05-27 07:32:11 +0000163" The window buffer size and container format.\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200164" zdict\n"
165" The predefined compression dictionary. This must be the same\n"
166" dictionary as used by the compressor that produced the input data.");
167
168#define ZLIB_DECOMPRESSOBJ_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700169 {"decompressobj", (PyCFunction)zlib_decompressobj, METH_FASTCALL, zlib_decompressobj__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200170
171static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300172zlib_decompressobj_impl(PyObject *module, int wbits, PyObject *zdict);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200173
174static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700175zlib_decompressobj(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200176{
177 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300178 static const char * const _keywords[] = {"wbits", "zdict", NULL};
179 static _PyArg_Parser _parser = {"|iO:decompressobj", _keywords, 0};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200180 int wbits = MAX_WBITS;
181 PyObject *zdict = NULL;
182
Victor Stinner37e4ef72016-09-09 20:00:13 -0700183 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300184 &wbits, &zdict)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200185 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300186 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200187 return_value = zlib_decompressobj_impl(module, wbits, zdict);
188
189exit:
190 return return_value;
191}
192
193PyDoc_STRVAR(zlib_Compress_compress__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800194"compress($self, data, /)\n"
195"--\n"
196"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200197"Returns a bytes object containing compressed data.\n"
198"\n"
199" data\n"
200" Binary data to be compressed.\n"
201"\n"
202"After calling this function, some of the input data may still\n"
203"be stored in internal buffers for later processing.\n"
204"Call the flush() method to clear these buffers.");
205
206#define ZLIB_COMPRESS_COMPRESS_METHODDEF \
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300207 {"compress", (PyCFunction)zlib_Compress_compress, METH_O, zlib_Compress_compress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200208
209static PyObject *
210zlib_Compress_compress_impl(compobject *self, Py_buffer *data);
211
212static PyObject *
Serhiy Storchaka92e8af62015-04-04 00:12:11 +0300213zlib_Compress_compress(compobject *self, PyObject *arg)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200214{
215 PyObject *return_value = NULL;
216 Py_buffer data = {NULL, NULL};
217
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300218 if (!PyArg_Parse(arg, "y*:compress", &data)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200219 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300220 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200221 return_value = zlib_Compress_compress_impl(self, &data);
222
223exit:
224 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300225 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200226 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300227 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200228
229 return return_value;
230}
231
232PyDoc_STRVAR(zlib_Decompress_decompress__doc__,
Serhiy Storchaka15f32282016-08-15 10:06:16 +0300233"decompress($self, data, /, max_length=0)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800234"--\n"
235"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200236"Return a bytes object containing the decompressed version of the data.\n"
237"\n"
238" data\n"
239" The binary data to decompress.\n"
240" max_length\n"
241" The maximum allowable length of the decompressed data.\n"
242" Unconsumed input data will be stored in\n"
243" the unconsumed_tail attribute.\n"
244"\n"
245"After calling this function, some of the input data may still be stored in\n"
246"internal buffers for later processing.\n"
247"Call the flush() method to clear these buffers.");
248
249#define ZLIB_DECOMPRESS_DECOMPRESS_METHODDEF \
Victor Stinner37e4ef72016-09-09 20:00:13 -0700250 {"decompress", (PyCFunction)zlib_Decompress_decompress, METH_FASTCALL, zlib_Decompress_decompress__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200251
252static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400253zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
Martin Panter84544c12016-07-23 03:02:07 +0000254 Py_ssize_t max_length);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200255
256static PyObject *
Victor Stinner37e4ef72016-09-09 20:00:13 -0700257zlib_Decompress_decompress(compobject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200258{
259 PyObject *return_value = NULL;
Serhiy Storchaka15f32282016-08-15 10:06:16 +0300260 static const char * const _keywords[] = {"", "max_length", NULL};
261 static _PyArg_Parser _parser = {"y*|O&:decompress", _keywords, 0};
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200262 Py_buffer data = {NULL, NULL};
Martin Panter84544c12016-07-23 03:02:07 +0000263 Py_ssize_t max_length = 0;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200264
Victor Stinner37e4ef72016-09-09 20:00:13 -0700265 if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser,
Martin Panter525a9492016-07-23 03:39:49 +0000266 &data, ssize_t_converter, &max_length)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200267 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300268 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200269 return_value = zlib_Decompress_decompress_impl(self, &data, max_length);
270
271exit:
272 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300273 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200274 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300275 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200276
277 return return_value;
278}
279
280PyDoc_STRVAR(zlib_Compress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800281"flush($self, mode=zlib.Z_FINISH, /)\n"
282"--\n"
283"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200284"Return a bytes object containing any remaining compressed data.\n"
285"\n"
286" mode\n"
287" One of the constants Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH.\n"
288" If mode == Z_FINISH, the compressor object can no longer be\n"
289" used after calling the flush() method. Otherwise, more data\n"
290" can still be compressed.");
291
292#define ZLIB_COMPRESS_FLUSH_METHODDEF \
293 {"flush", (PyCFunction)zlib_Compress_flush, METH_VARARGS, zlib_Compress_flush__doc__},
294
295static PyObject *
296zlib_Compress_flush_impl(compobject *self, int mode);
297
298static PyObject *
299zlib_Compress_flush(compobject *self, PyObject *args)
300{
301 PyObject *return_value = NULL;
302 int mode = Z_FINISH;
303
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300304 if (!PyArg_ParseTuple(args, "|i:flush",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300305 &mode)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200306 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300307 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200308 return_value = zlib_Compress_flush_impl(self, mode);
309
310exit:
311 return return_value;
312}
313
Larry Hastings7726ac92014-01-31 22:03:12 -0800314#if defined(HAVE_ZLIB_COPY)
315
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200316PyDoc_STRVAR(zlib_Compress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800317"copy($self, /)\n"
318"--\n"
319"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200320"Return a copy of the compression object.");
321
322#define ZLIB_COMPRESS_COPY_METHODDEF \
323 {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__},
324
325static PyObject *
326zlib_Compress_copy_impl(compobject *self);
327
328static PyObject *
329zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
330{
331 return zlib_Compress_copy_impl(self);
332}
333
Larry Hastings7726ac92014-01-31 22:03:12 -0800334#endif /* defined(HAVE_ZLIB_COPY) */
335
Larry Hastings7726ac92014-01-31 22:03:12 -0800336#if defined(HAVE_ZLIB_COPY)
337
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200338PyDoc_STRVAR(zlib_Decompress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800339"copy($self, /)\n"
340"--\n"
341"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200342"Return a copy of the decompression object.");
343
344#define ZLIB_DECOMPRESS_COPY_METHODDEF \
345 {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__},
346
347static PyObject *
348zlib_Decompress_copy_impl(compobject *self);
349
350static PyObject *
351zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
352{
353 return zlib_Decompress_copy_impl(self);
354}
355
Larry Hastings7726ac92014-01-31 22:03:12 -0800356#endif /* defined(HAVE_ZLIB_COPY) */
357
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200358PyDoc_STRVAR(zlib_Decompress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800359"flush($self, length=zlib.DEF_BUF_SIZE, /)\n"
360"--\n"
361"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200362"Return a bytes object containing any remaining decompressed data.\n"
363"\n"
364" length\n"
365" the initial size of the output buffer.");
366
367#define ZLIB_DECOMPRESS_FLUSH_METHODDEF \
368 {"flush", (PyCFunction)zlib_Decompress_flush, METH_VARARGS, zlib_Decompress_flush__doc__},
369
370static PyObject *
Martin Panter84544c12016-07-23 03:02:07 +0000371zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200372
373static PyObject *
374zlib_Decompress_flush(compobject *self, PyObject *args)
375{
376 PyObject *return_value = NULL;
Martin Panter84544c12016-07-23 03:02:07 +0000377 Py_ssize_t length = DEF_BUF_SIZE;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200378
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300379 if (!PyArg_ParseTuple(args, "|O&:flush",
Martin Panter525a9492016-07-23 03:39:49 +0000380 ssize_t_converter, &length)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200381 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300382 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200383 return_value = zlib_Decompress_flush_impl(self, length);
384
385exit:
386 return return_value;
387}
388
389PyDoc_STRVAR(zlib_adler32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800390"adler32($module, data, value=1, /)\n"
391"--\n"
392"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200393"Compute an Adler-32 checksum of data.\n"
394"\n"
395" value\n"
396" Starting value of the checksum.\n"
397"\n"
398"The returned checksum is an integer.");
399
400#define ZLIB_ADLER32_METHODDEF \
401 {"adler32", (PyCFunction)zlib_adler32, METH_VARARGS, zlib_adler32__doc__},
402
403static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300404zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200405
406static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300407zlib_adler32(PyObject *module, PyObject *args)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200408{
409 PyObject *return_value = NULL;
410 Py_buffer data = {NULL, NULL};
411 unsigned int value = 1;
412
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300413 if (!PyArg_ParseTuple(args, "y*|I:adler32",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300414 &data, &value)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200415 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300416 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200417 return_value = zlib_adler32_impl(module, &data, value);
418
419exit:
420 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300421 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200422 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300423 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200424
425 return return_value;
426}
427
428PyDoc_STRVAR(zlib_crc32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800429"crc32($module, data, value=0, /)\n"
430"--\n"
431"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200432"Compute a CRC-32 checksum of data.\n"
433"\n"
434" value\n"
435" Starting value of the checksum.\n"
436"\n"
437"The returned checksum is an integer.");
438
439#define ZLIB_CRC32_METHODDEF \
440 {"crc32", (PyCFunction)zlib_crc32, METH_VARARGS, zlib_crc32__doc__},
441
442static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300443zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200444
445static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300446zlib_crc32(PyObject *module, PyObject *args)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200447{
448 PyObject *return_value = NULL;
449 Py_buffer data = {NULL, NULL};
450 unsigned int value = 0;
451
Serhiy Storchaka247789c2015-04-24 00:40:51 +0300452 if (!PyArg_ParseTuple(args, "y*|I:crc32",
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300453 &data, &value)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200454 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300455 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200456 return_value = zlib_crc32_impl(module, &data, value);
457
458exit:
459 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300460 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200461 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300462 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200463
464 return return_value;
465}
Larry Hastings0759f842015-04-03 13:09:02 -0700466
467#ifndef ZLIB_COMPRESS_COPY_METHODDEF
468 #define ZLIB_COMPRESS_COPY_METHODDEF
469#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
Victor Stinner37e4ef72016-09-09 20:00:13 -0700470/*[clinic end generated code: output=3a4e2bfe750423a3 input=a9049054013a1b77]*/