return PyLong_FromSsize_t(self->pos);
}
+static PyObject *
+read_bytes(bytesio *self, Py_ssize_t size)
+{
+ char *output;
+
+ assert(self->buf != NULL);
+ assert(size <= self->string_size);
+ if (size > 1 &&
+ self->pos == 0 && size == PyBytes_GET_SIZE(self->buf) &&
+ self->exports == 0) {
+ self->pos += size;
+ Py_INCREF(self->buf);
+ return self->buf;
+ }
+
+ output = PyBytes_AS_STRING(self->buf) + self->pos;
+ self->pos += size;
+ return PyBytes_FromStringAndSize(output, size);
+}
+
PyDoc_STRVAR(read_doc,
- "read([size]) -> read at most size bytes, returned as a string.\n"
+ "read([size]) -> read at most size bytes, returned as a bytes object.\n"
"\n"
"If the size argument is negative, read until EOF is reached.\n"
- "Return an empty string at EOF.");
+ "Return an empty bytes object at EOF.");
static PyObject *
bytesio_read(bytesio *self, PyObject *args)