summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--msgpack/_msgpack.pyx12
1 files changed, 12 insertions, 0 deletions
diff --git a/msgpack/_msgpack.pyx b/msgpack/_msgpack.pyx
index c9f5e31..d7ea4b4 100644
--- a/msgpack/_msgpack.pyx
+++ b/msgpack/_msgpack.pyx
@@ -455,6 +455,18 @@ cdef class Unpacker(object):
else:
raise ValueError("Unpack failed: error = %d" % (ret,))
+ def read_bytes(self, Py_ssize_t nbytes):
+ """read a specified number of raw bytes from the stream"""
+ cdef size_t nread
+ ret = ''
+ while len(ret) < nbytes and self.file_like is not None:
+ if self.buf_head == self.buf_tail:
+ self.fill_buffer()
+ nread = min(self.buf_tail - self.buf_head, nbytes - len(ret))
+ ret += PyBytes_FromStringAndSize(self.buf + self.buf_head, nread)
+ self.buf_head += nread
+ return ret
+
def __iter__(self):
return self