MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / JM_BufferFromBytes

Function JM_BufferFromBytes

src/__init__.py:18437–18452  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

18435
18436
18437def 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
18455def JM_FLOAT_ITEM(obj, idx):

Callers 14

_setAPMethod · 0.85
update_fileMethod · 0.85
_add_treeitemMethod · 0.85
_add_ziptarmemoryMethod · 0.85
_embfile_addMethod · 0.85
_embfile_updMethod · 0.85
journal_loadMethod · 0.85
update_streamMethod · 0.85
_add_file_annotMethod · 0.85
_insert_imageMethod · 0.85
__init__Method · 0.85
JM_get_fontFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…