fix: binary file corruption#230
Merged
Merged
Conversation
**Location:** `src/blob.ts`, line 28
The code was reading files with UTF-8 text encoding:
```typescript
fs.createReadStream(this.absolutePath, { encoding: 'utf8' })
```
Images are **binary files** containing arbitrary byte values (0-255). The UTF-8 encoding option tells Node.js to:
1. Interpret the binary data as UTF-8 text
2. Drop any byte sequences that are not valid UTF-8
This causes data loss because:
- Valid UTF-8 sequences are 1-4 bytes depending on the character
- Many byte combinations in binary files are invalid UTF-8 sequences
- These invalid bytes are silently dropped by the UTF-8 decoder
- The resulting file is corrupted (missing bytes)
The base64-encoder was converting base64 strings back to buffers before pushing them to the stream, which caused them to be re-encoded as UTF-8 bytes. This corrupted binary files (images, PDFs, etc.) when they were committed and pushed to GitHub. Changes: - base64-encoder.ts: Push base64 strings directly instead of converting them back to buffers. This prevents the double-encoding that was corrupting binary data. - blob.ts: Remove UTF-8 encoding from file stream reading. Files are now read as raw buffers, which is necessary for the base64 encoder to work correctly with both text and binary files. The fix ensures that: - Binary files (PNG, JPG, PDF, etc.) are encoded without corruption - Text files continue to work correctly - The action properly base64 encodes file content for GitHub API Fixes image corruption when committing and pushing images to GitHub
…ng a fixture with non-UTF-8 byte sequences to guard against silent data corruption
57bf0c9 to
be96498
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #230 +/- ##
=======================================
Coverage 97.31% 97.31%
=======================================
Files 11 11
Lines 261 261
Branches 59 59
=======================================
Hits 254 254
Misses 7 7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
closes #210