Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite option #11

Open
camlafit opened this issue May 2, 2023 · 1 comment
Open

Overwrite option #11

camlafit opened this issue May 2, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@camlafit
Copy link

camlafit commented May 2, 2023

Hi

I've used a personnal script with more or less same feature. As your code looks better I'll change to it :)

A feature miss in my use cas overwrite option. In many case I assume optimization should be done on the original file. Is it possible to add this behavior ?

Thanks

camlafit added a commit to camlafit/shrinkpdf that referenced this issue May 23, 2023
@aklomp
Copy link
Owner

aklomp commented May 25, 2023

Hi, thanks for the suggestion. I think it often makes sense to overwrite the original file, but adding that feature is more difficult than it looks.

Overwriting the input file requires creating a temporary file to hold the outputs, because I assume Ghostscript requires the input and output files to be distinct. In any case we need to keep a copy of the original file in case the output turns out to be larger, and we want to restore the original file.

Temporary files are really difficult to create in a portable way in Posix shell. Even worse, to do it properly you'd need to trap signals to clean up the temporary file if the user aborts the script. It quickly becomes a major headache and complication, requiring a lot of machinery and probably sacrificing cross-platform portability.

So that's why I haven't implemented this seemingly obvious and useful feature. I've chosen to keep the script simple and focused, and this feature just invites too much complexity. The end user can probably script around it easily by creating a small wrapper script that works on their platform (using some non-portable tool like mktemp), but I don't think there's an easy way to supply that functionality out of the box.

I'd be interested in seeing a pull request that implements this in a portable way though.

@aklomp aklomp self-assigned this May 25, 2023
@aklomp aklomp added the enhancement New feature or request label May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants