Add an option to shrink the PDF file where it is#23
Add an option to shrink the PDF file where it is#23arwarw wants to merge 2 commits intoaklomp:masterfrom
Conversation
Add an option -i to replace the input file with the shrunk output (if smaller). This creates a temporary directory in a secure and portable manner, cleaning it up afterwards. The temporary directory is created using 'mktemp' if present, otherwise the less secure method of including the PID, current time and possibly (if available) $RANDOM is used. The directory is removed upon exit, but carefully: 'rm -fr' is only executed on a then-empty directory after output.pdf has been removed. This could leak directories, but I consider that less of a problem than possibly removing something important.
|
Hello, Looks nice, I was looking for a way to manage in‑place behaviour. It could also be interesting if, when -o is not set, it implied in‑place mode by default. |
Thanks!
I made a habit out of always using temporary directories instead of files because it's easier to clean up and less prone to race conditions in case one needs multiple files. I guess in this case one could also just use a file.
Yes, maybe. On the other hand I'm not sure if existing users would appreciate their files being overwritten in the new behaviour. I thought it would be better to have an explicit switch for that behavior. |
This makes use of a temporary directory that is securely (as far as possible) created and cleaned up.