Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions msgpack/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,10 @@ def _reserve(self, n, raise_outofdata=True):
return

if self._feeding:
self._buff_i = self._buf_checkpoint
raise OutOfData
if raise_outofdata:
self._buff_i = self._buf_checkpoint
raise OutOfData
return

# Strip buffer before checkpoint before reading file.
if self._buf_checkpoint > 0:
Expand Down
17 changes: 16 additions & 1 deletion test/test_sequnpack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import io

from pytest import raises
from pytest import mark, raises

from msgpack import BufferFull, Unpacker, pack, packb
from msgpack.exceptions import OutOfData
Expand Down Expand Up @@ -169,3 +169,18 @@ def test_unpack_tell():
m2 = next(unpacker)
assert m == m2
assert o == unpacker.tell()


@mark.parametrize("data", [b"", b"ab"])
def test_readbytes_short_feed(data):
unpacker = Unpacker()
unpacker.feed(packb(42) + data)
assert unpacker.unpack() == 42
assert unpacker.read_bytes(5) == data
assert unpacker.tell() == 1 + len(data)
assert unpacker.read_bytes(5) == b""
assert unpacker.tell() == 1 + len(data)

unpacker.feed(packb("next"))
assert unpacker.unpack() == "next"
assert unpacker.tell() == 1 + len(data) + len(packb("next"))
Loading