Make fz_buffer from a PyBytes, PyByteArray or io.BytesIO object. If a text io.BytesIO, we convert to binary by encoding as utf8.
(stream)
| 18435 | |
| 18436 | |
| 18437 | def JM_BufferFromBytes(stream): |
| 18438 | ''' |
| 18439 | Make fz_buffer from a PyBytes, PyByteArray or io.BytesIO object. If a text |
| 18440 | io.BytesIO, we convert to binary by encoding as utf8. |
| 18441 | ''' |
| 18442 | if isinstance(stream, (bytes, bytearray)): |
| 18443 | data = stream |
| 18444 | elif hasattr(stream, 'getvalue'): |
| 18445 | data = stream.getvalue() |
| 18446 | if isinstance(data, str): |
| 18447 | data = data.encode('utf-8') |
| 18448 | if not isinstance(data, (bytes, bytearray)): |
| 18449 | raise Exception(f'.getvalue() returned unexpected type: {type(data)}') |
| 18450 | else: |
| 18451 | return mupdf.FzBuffer() |
| 18452 | return mupdf.fz_new_buffer_from_copied_data(data) |
| 18453 | |
| 18454 | |
| 18455 | def JM_FLOAT_ITEM(obj, idx): |
no outgoing calls
no test coverage detected
searching dependent graphs…