41 |
41 |
42 PyObject_Del(self); |
42 PyObject_Del(self); |
43 } |
43 } |
44 |
44 |
45 static ZstdCompressionReader* reader_enter(ZstdCompressionReader* self) { |
45 static ZstdCompressionReader* reader_enter(ZstdCompressionReader* self) { |
46 size_t zresult; |
|
47 |
|
48 if (self->entered) { |
46 if (self->entered) { |
49 PyErr_SetString(PyExc_ValueError, "cannot __enter__ multiple times"); |
47 PyErr_SetString(PyExc_ValueError, "cannot __enter__ multiple times"); |
50 return NULL; |
|
51 } |
|
52 |
|
53 zresult = ZSTD_CCtx_setPledgedSrcSize(self->compressor->cctx, self->sourceSize); |
|
54 if (ZSTD_isError(zresult)) { |
|
55 PyErr_Format(ZstdError, "error setting source size: %s", |
|
56 ZSTD_getErrorName(zresult)); |
|
57 return NULL; |
48 return NULL; |
58 } |
49 } |
59 |
50 |
60 self->entered = 1; |
51 self->entered = 1; |
61 |
52 |
331 PyDoc_STR("Enter a compression context") }, |
308 PyDoc_STR("Enter a compression context") }, |
332 { "__exit__", (PyCFunction)reader_exit, METH_VARARGS, |
309 { "__exit__", (PyCFunction)reader_exit, METH_VARARGS, |
333 PyDoc_STR("Exit a compression context") }, |
310 PyDoc_STR("Exit a compression context") }, |
334 { "close", (PyCFunction)reader_close, METH_NOARGS, |
311 { "close", (PyCFunction)reader_close, METH_NOARGS, |
335 PyDoc_STR("Close the stream so it cannot perform any more operations") }, |
312 PyDoc_STR("Close the stream so it cannot perform any more operations") }, |
336 { "closed", (PyCFunction)reader_closed, METH_NOARGS, |
|
337 PyDoc_STR("Whether stream is closed") }, |
|
338 { "flush", (PyCFunction)reader_flush, METH_NOARGS, PyDoc_STR("no-ops") }, |
313 { "flush", (PyCFunction)reader_flush, METH_NOARGS, PyDoc_STR("no-ops") }, |
339 { "isatty", (PyCFunction)reader_isatty, METH_NOARGS, PyDoc_STR("Returns False") }, |
314 { "isatty", (PyCFunction)reader_isatty, METH_NOARGS, PyDoc_STR("Returns False") }, |
340 { "readable", (PyCFunction)reader_readable, METH_NOARGS, |
315 { "readable", (PyCFunction)reader_readable, METH_NOARGS, |
341 PyDoc_STR("Returns True") }, |
316 PyDoc_STR("Returns True") }, |
342 { "read", (PyCFunction)reader_read, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("read compressed data") }, |
317 { "read", (PyCFunction)reader_read, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("read compressed data") }, |
350 { "writable", (PyCFunction)reader_writable, METH_NOARGS, |
325 { "writable", (PyCFunction)reader_writable, METH_NOARGS, |
351 PyDoc_STR("Returns False") }, |
326 PyDoc_STR("Returns False") }, |
352 { "write", reader_write, METH_VARARGS, PyDoc_STR("Raises OSError") }, |
327 { "write", reader_write, METH_VARARGS, PyDoc_STR("Raises OSError") }, |
353 { "writelines", reader_writelines, METH_VARARGS, PyDoc_STR("Not implemented") }, |
328 { "writelines", reader_writelines, METH_VARARGS, PyDoc_STR("Not implemented") }, |
354 { NULL, NULL } |
329 { NULL, NULL } |
|
330 }; |
|
331 |
|
332 static PyMemberDef reader_members[] = { |
|
333 { "closed", T_BOOL, offsetof(ZstdCompressionReader, closed), |
|
334 READONLY, "whether stream is closed" }, |
|
335 { NULL } |
355 }; |
336 }; |
356 |
337 |
357 PyTypeObject ZstdCompressionReaderType = { |
338 PyTypeObject ZstdCompressionReaderType = { |
358 PyVarObject_HEAD_INIT(NULL, 0) |
339 PyVarObject_HEAD_INIT(NULL, 0) |
359 "zstd.ZstdCompressionReader", /* tp_name */ |
340 "zstd.ZstdCompressionReader", /* tp_name */ |
381 0, /* tp_richcompare */ |
362 0, /* tp_richcompare */ |
382 0, /* tp_weaklistoffset */ |
363 0, /* tp_weaklistoffset */ |
383 reader_iter, /* tp_iter */ |
364 reader_iter, /* tp_iter */ |
384 reader_iternext, /* tp_iternext */ |
365 reader_iternext, /* tp_iternext */ |
385 reader_methods, /* tp_methods */ |
366 reader_methods, /* tp_methods */ |
386 0, /* tp_members */ |
367 reader_members, /* tp_members */ |
387 0, /* tp_getset */ |
368 0, /* tp_getset */ |
388 0, /* tp_base */ |
369 0, /* tp_base */ |
389 0, /* tp_dict */ |
370 0, /* tp_dict */ |
390 0, /* tp_descr_get */ |
371 0, /* tp_descr_get */ |
391 0, /* tp_descr_set */ |
372 0, /* tp_descr_set */ |