diff options
author | James R. Barlow <jim@purplerock.ca> | 2019-05-01 22:55:40 -0700 |
---|---|---|
committer | James R. Barlow <jim@purplerock.ca> | 2019-05-01 22:55:40 -0700 |
commit | 984d60198b21328d658acbf8d763de10c0850db5 (patch) | |
tree | daf58a53c472b297d4b85af7e6bb9aa566261066 /tests | |
parent | 308312cc438c62ad6fdd6eccabf9ad95a53d7de4 (diff) |
Eliminate intermediate buffer when writing to Python stream
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_io.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_io.py b/tests/test_io.py new file mode 100644 index 0000000..4ce8eb5 --- /dev/null +++ b/tests/test_io.py @@ -0,0 +1,26 @@ +import pytest + +from pikepdf import Pdf +from io import BytesIO + + +@pytest.fixture +def sandwich(resources): + # Has XMP, docinfo, <?adobe-xap-filters esc="CRLF"?>, shorthand attribute XMP + return Pdf.open(resources / 'sandwich.pdf') + + +class LimitedBytesIO(BytesIO): + """Version of BytesIO that only accepts small reads/writes""" + + def write(self, b): + amt = min(len(b), 100) + return super().write(b[:amt]) + + +def test_weird_output_stream(sandwich): + bio = BytesIO() + lbio = LimitedBytesIO() + sandwich.save(bio, static_id=True) + sandwich.save(lbio, static_id=True) + assert bio.getvalue() == lbio.getvalue() |