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

Function embedded_get

src/__main__.py:347–365  ·  view source on GitHub ↗

Retrieve contents of an embedded file.

(args)

Source from the content-addressed store, hash-verified

345
346
347def embedded_get(args):
348 """Retrieve contents of an embedded file."""
349 doc = open_file(args.input, args.password, pdf=True)
350 try:
351 stream = doc.embfile_get(args.name)
352 d = doc.embfile_info(args.name)
353 except (ValueError, pymupdf.mupdf.FzErrorBase) as e:
354 sys.exit(f'no such embedded file {args.name!r}: {e}')
355 filename = args.output if args.output else d["filename"]
356 if not args.unsafe and not args.output:
357 if os.path.exists(filename):
358 sys.exit(f'refusing to overwrite existing file with stored name: {filename}')
359 filename_abs = os.path.abspath(filename)
360 if not filename_abs.startswith(os.getcwd() + os.sep):
361 sys.exit(f'refusing to write stored name outside current directory: {filename}')
362 with open(filename, "wb") as output:
363 output.write(stream)
364 pymupdf.message(f"saved entry '{args.name}' as '{filename}'")
365 doc.close()
366
367
368def embedded_add(args):

Callers

nothing calls this directly

Calls 5

embfile_getMethod · 0.80
embfile_infoMethod · 0.80
open_fileFunction · 0.70
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…