summaryrefslogtreecommitdiff
path: root/msgpack/_unpacker.pyx
diff options
context:
space:
mode:
authorjfolz <theriddling@gmail.com>2020-06-08 05:14:50 +0200
committerGitHub <noreply@github.com>2020-06-08 12:14:50 +0900
commitc1b1a23f62d5e0ec39a1910d2e9580ce1c13a1cf (patch)
tree9726bba0edf80ba9515495c315d7966f7b7aa37e /msgpack/_unpacker.pyx
parentb04690012d5d77cfe5074893686c4d55ec780300 (diff)
downloadmsgpack-python-c1b1a23f62d5e0ec39a1910d2e9580ce1c13a1cf.tar.gz
Fix Unpacker.tell() (#427)
Fixes #426. Co-authored-by: folz <joachim.folz@dfki.de>
Diffstat (limited to 'msgpack/_unpacker.pyx')
-rw-r--r--msgpack/_unpacker.pyx10
1 files changed, 8 insertions, 2 deletions
diff --git a/msgpack/_unpacker.pyx b/msgpack/_unpacker.pyx
index 43c93a2..4340e04 100644
--- a/msgpack/_unpacker.pyx
+++ b/msgpack/_unpacker.pyx
@@ -484,8 +484,10 @@ cdef class Unpacker(object):
nread = min(self.buf_tail - self.buf_head, nbytes)
ret = PyBytes_FromStringAndSize(self.buf + self.buf_head, nread)
self.buf_head += nread
- if len(ret) < nbytes and self.file_like is not None:
- ret += self.file_like.read(nbytes - len(ret))
+ if nread < nbytes and self.file_like is not None:
+ ret += self.file_like.read(nbytes - nread)
+ nread = len(ret)
+ self.stream_offset += nread
return ret
def unpack(self):
@@ -519,6 +521,10 @@ cdef class Unpacker(object):
return self._unpack(read_map_header)
def tell(self):
+ """Returns the current position of the Unpacker in bytes, i.e., the
+ number of bytes that were read from the input, also the starting
+ position of the next object.
+ """
return self.stream_offset
def __iter__(self):