Retrieve contents of an embedded file.
(args)
| 345 | |
| 346 | |
| 347 | def 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 | |
| 368 | def embedded_add(args): |
nothing calls this directly
no test coverage detected
searching dependent graphs…