Repository navigation
Truncate existing output files before writing - #115
Merged
Merged
Conversation
Owner
|
@mertkayacs thanks for the contribution. |
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.
If the output file already exists and the new image is smaller, caire leaves the end of the old file in place.
pathToFileopens the output withos.O_CREATE|os.O_WRONLYand noos.O_TRUNC.After the second run
out.pngis still 430,993 bytes. A fresh 200px output is 201,064 bytes, so about 230 KB of the first image stays after the PNG's IEND chunk. Viewers stop reading at IEND, so the picture looks right, but the file keeps the old bytes.The fix adds
os.O_TRUNC. The test puts a 1 MB file at the output path, runs the normal write path and checks that the result is the same size as a fresh write.go vetand the tests pass on Go 1.22 and 1.26 (face detection tests left to CI).