Fix Unpacker.tell() (#427)

Fixes #426.

Co-authored-by: folz <joachim.folz@dfki.de>
This commit is contained in:
jfolz 2020-06-08 05:14:50 +02:00 committed by GitHub
parent b04690012d
commit c1b1a23f62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 9 deletions

View file

@ -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):