Accept files from stdin, write safe PDFs to stdout - #1528
Open
apyrgio wants to merge 6 commits into
Open
Conversation
Remove the private _validate_* functions and their public wrapper functions that existed to work around a Click 7.x bug (issue #206). Click 7.x is no longer supported, so these wrappers are unnecessary. Promote the @errors.handle_document_errors-decorated functions directly to public names.
The ASCII art banner was printing to stdout, which would interfere with piping safe PDF data. Route all banner output to stderr instead, and update the corresponding test to read from stderr.
All human-readable status output (print_header, settings messages, OCR language validation, container image warnings, failed document display) now goes to stderr via click.echo(..., err=True), keeping stdout clean for potential PDF data output. Also use str(document) for failed doc display instead of document.input_filename, which is preparatory for data-based documents where input_filename would raise.
Extend the Document class to accept raw bytes via a new 'data' parameter instead of requiring a file path. This is the foundation for stdin support. - New 'data' parameter in __init__ (default None, backward-compatible) - Constructor requires either input_filename or data - New Document.from_stdin() classmethod reads from sys.stdin.buffer - New open() method returns BinaryIO (file or BytesIO) - New write() method writes to stdout or output file - New sanitized_input_filename property - announce_id() handles both file and stdin documents - __eq__, __hash__, __str__ handle data-based documents - Add DangerzoneCore.add_document_from_stdin() - Update tests for new constructor requirements
Decouple the isolation provider from file-based I/O by using the Document abstraction methods: - document.open() instead of open(document.input_filename, 'rb') - document.write() instead of safe_doc.save() + os.replace() This enables the provider to work with data-based documents (stdin) without modification.
Implement stdin/stdout I/O for the Dangerzone CLI. - Add _initialize_documents() handling stdin detection, validation, and document creation - Accept '-' as a filename to explicitly read from stdin - Accept implicit stdin when no filenames given and stdin is piped - Write safe PDF to stdout when no --output-filename is specified - Refuse to write to a terminal without --output-filename - Reject --archive with stdin input - Update @click.command() help text mentioning stdin - Add STDIO_DESCRIPTOR constant and skip validation for '-' - Add TestCliIO test class covering all stdin/stdout scenarios Fixes #1522
apyrgio
force-pushed
the
1522-stdin-stdout
branch
from
July 21, 2026 09:43
5d37a5a to
d5e3c95
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dangerzone CLI now accepts documents via stdin and writes safe PDFs to stdout, following standard Unix pipe conventions:
All status output (banner, progress, errors) goes to stderr so stdout stays clean for PDF data. We also take extra care to detect when we can read from stdin and when we can write to stdout, so that we don't mess with the user's TTY.
Fixes #1522
Refs #206