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

Function JM_update_stream

src/__init__.py:21905–21926  ·  view source on GitHub ↗

update a stream object compress stream when beneficial

(doc, obj, buffer_, compress)

Source from the content-addressed store, hash-verified

21903
21904
21905def JM_update_stream(doc, obj, buffer_, compress):
21906 '''
21907 update a stream object
21908 compress stream when beneficial
21909 '''
21910 if compress:
21911 length, _ = mupdf.fz_buffer_storage(buffer_)
21912 if length > 30: # ignore small stuff
21913 buffer_compressed = JM_compress_buffer(buffer_)
21914 assert isinstance(buffer_compressed, mupdf.FzBuffer)
21915 if buffer_compressed.m_internal:
21916 length_compressed, _ = mupdf.fz_buffer_storage(buffer_compressed)
21917 if length_compressed < length: # was it worth the effort?
21918 mupdf.pdf_dict_put(
21919 obj,
21920 mupdf.PDF_ENUM_NAME_Filter,
21921 mupdf.PDF_ENUM_NAME_FlateDecode,
21922 )
21923 mupdf.pdf_update_stream(doc, obj, buffer_compressed, 1)
21924 return
21925
21926 mupdf.pdf_update_stream(doc, obj, buffer_, 0)
21927
21928
21929def JM_xobject_from_page(pdfout, fsrcpage, xref, gmap):

Callers 8

_setAPMethod · 0.85
update_fileMethod · 0.85
_embfile_updMethod · 0.85
fullcopy_pageMethod · 0.85
set_xml_metadataMethod · 0.85
update_streamMethod · 0.85
JM_embed_fileFunction · 0.85
JM_xobject_from_pageFunction · 0.85

Calls 1

JM_compress_bufferFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…