blob: 20e7f2ae27027151b2a2ab10a7b5bdbda06b1d3f [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 Stinner3e1fad62017-01-17 01:29:01 +010031 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +010076 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100141 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100183 if (!_PyArg_ParseStackAndKeywords(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 Stinner3e1fad62017-01-17 01:29:01 +0100265 if (!_PyArg_ParseStackAndKeywords(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 \
Victor Stinner259f0e42017-01-17 01:35:17 +0100293 {"flush", (PyCFunction)zlib_Compress_flush, METH_FASTCALL, zlib_Compress_flush__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200294
295static PyObject *
296zlib_Compress_flush_impl(compobject *self, int mode);
297
298static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100299zlib_Compress_flush(compobject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200300{
301 PyObject *return_value = NULL;
302 int mode = Z_FINISH;
303
Sylvain74453812017-06-10 06:51:48 +0200304 if (!_PyArg_NoStackKeywords("flush", kwnames)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200305 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300306 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100307
Sylvain74453812017-06-10 06:51:48 +0200308 if (!_PyArg_ParseStack(args, nargs, "|i:flush",
309 &mode)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100310 goto exit;
311 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200312 return_value = zlib_Compress_flush_impl(self, mode);
313
314exit:
315 return return_value;
316}
317
Larry Hastings7726ac92014-01-31 22:03:12 -0800318#if defined(HAVE_ZLIB_COPY)
319
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200320PyDoc_STRVAR(zlib_Compress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800321"copy($self, /)\n"
322"--\n"
323"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200324"Return a copy of the compression object.");
325
326#define ZLIB_COMPRESS_COPY_METHODDEF \
327 {"copy", (PyCFunction)zlib_Compress_copy, METH_NOARGS, zlib_Compress_copy__doc__},
328
329static PyObject *
330zlib_Compress_copy_impl(compobject *self);
331
332static PyObject *
333zlib_Compress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
334{
335 return zlib_Compress_copy_impl(self);
336}
337
Larry Hastings7726ac92014-01-31 22:03:12 -0800338#endif /* defined(HAVE_ZLIB_COPY) */
339
Larry Hastings7726ac92014-01-31 22:03:12 -0800340#if defined(HAVE_ZLIB_COPY)
341
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200342PyDoc_STRVAR(zlib_Decompress_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800343"copy($self, /)\n"
344"--\n"
345"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200346"Return a copy of the decompression object.");
347
348#define ZLIB_DECOMPRESS_COPY_METHODDEF \
349 {"copy", (PyCFunction)zlib_Decompress_copy, METH_NOARGS, zlib_Decompress_copy__doc__},
350
351static PyObject *
352zlib_Decompress_copy_impl(compobject *self);
353
354static PyObject *
355zlib_Decompress_copy(compobject *self, PyObject *Py_UNUSED(ignored))
356{
357 return zlib_Decompress_copy_impl(self);
358}
359
Larry Hastings7726ac92014-01-31 22:03:12 -0800360#endif /* defined(HAVE_ZLIB_COPY) */
361
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200362PyDoc_STRVAR(zlib_Decompress_flush__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800363"flush($self, length=zlib.DEF_BUF_SIZE, /)\n"
364"--\n"
365"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200366"Return a bytes object containing any remaining decompressed data.\n"
367"\n"
368" length\n"
369" the initial size of the output buffer.");
370
371#define ZLIB_DECOMPRESS_FLUSH_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100372 {"flush", (PyCFunction)zlib_Decompress_flush, METH_FASTCALL, zlib_Decompress_flush__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200373
374static PyObject *
Martin Panter84544c12016-07-23 03:02:07 +0000375zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200376
377static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100378zlib_Decompress_flush(compobject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200379{
380 PyObject *return_value = NULL;
Martin Panter84544c12016-07-23 03:02:07 +0000381 Py_ssize_t length = DEF_BUF_SIZE;
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200382
Sylvain74453812017-06-10 06:51:48 +0200383 if (!_PyArg_NoStackKeywords("flush", kwnames)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200384 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300385 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100386
Sylvain74453812017-06-10 06:51:48 +0200387 if (!_PyArg_ParseStack(args, nargs, "|O&:flush",
388 ssize_t_converter, &length)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100389 goto exit;
390 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200391 return_value = zlib_Decompress_flush_impl(self, length);
392
393exit:
394 return return_value;
395}
396
397PyDoc_STRVAR(zlib_adler32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800398"adler32($module, data, value=1, /)\n"
399"--\n"
400"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200401"Compute an Adler-32 checksum of data.\n"
402"\n"
403" value\n"
404" Starting value of the checksum.\n"
405"\n"
406"The returned checksum is an integer.");
407
408#define ZLIB_ADLER32_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100409 {"adler32", (PyCFunction)zlib_adler32, METH_FASTCALL, zlib_adler32__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200410
411static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300412zlib_adler32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200413
414static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100415zlib_adler32(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200416{
417 PyObject *return_value = NULL;
418 Py_buffer data = {NULL, NULL};
419 unsigned int value = 1;
420
Sylvain74453812017-06-10 06:51:48 +0200421 if (!_PyArg_NoStackKeywords("adler32", kwnames)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200422 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300423 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100424
Sylvain74453812017-06-10 06:51:48 +0200425 if (!_PyArg_ParseStack(args, nargs, "y*|I:adler32",
426 &data, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100427 goto exit;
428 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200429 return_value = zlib_adler32_impl(module, &data, value);
430
431exit:
432 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300433 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200434 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300435 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200436
437 return return_value;
438}
439
440PyDoc_STRVAR(zlib_crc32__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800441"crc32($module, data, value=0, /)\n"
442"--\n"
443"\n"
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200444"Compute a CRC-32 checksum of data.\n"
445"\n"
446" value\n"
447" Starting value of the checksum.\n"
448"\n"
449"The returned checksum is an integer.");
450
451#define ZLIB_CRC32_METHODDEF \
Victor Stinner259f0e42017-01-17 01:35:17 +0100452 {"crc32", (PyCFunction)zlib_crc32, METH_FASTCALL, zlib_crc32__doc__},
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200453
454static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300455zlib_crc32_impl(PyObject *module, Py_buffer *data, unsigned int value);
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200456
457static PyObject *
Victor Stinner259f0e42017-01-17 01:35:17 +0100458zlib_crc32(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200459{
460 PyObject *return_value = NULL;
461 Py_buffer data = {NULL, NULL};
462 unsigned int value = 0;
463
Sylvain74453812017-06-10 06:51:48 +0200464 if (!_PyArg_NoStackKeywords("crc32", kwnames)) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200465 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300466 }
Victor Stinner259f0e42017-01-17 01:35:17 +0100467
Sylvain74453812017-06-10 06:51:48 +0200468 if (!_PyArg_ParseStack(args, nargs, "y*|I:crc32",
469 &data, &value)) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100470 goto exit;
471 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200472 return_value = zlib_crc32_impl(module, &data, value);
473
474exit:
475 /* Cleanup for data */
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300476 if (data.obj) {
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200477 PyBuffer_Release(&data);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300478 }
Serhiy Storchaka2c5ddbe2014-01-27 00:03:31 +0200479
480 return return_value;
481}
Larry Hastings0759f842015-04-03 13:09:02 -0700482
483#ifndef ZLIB_COMPRESS_COPY_METHODDEF
484 #define ZLIB_COMPRESS_COPY_METHODDEF
485#endif /* !defined(ZLIB_COMPRESS_COPY_METHODDEF) */
Sylvain74453812017-06-10 06:51:48 +0200486/*[clinic end generated code: output=c7abf02e091bcad3 input=a9049054013a1b77]*/