Skip to content

Commit d2f2197

Browse files
committed
fix: image commits leads to invalid images
**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)
1 parent d76880d commit d2f2197

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/blob.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ export class Blob {
2626
throw new Error(`File does not exist, path: ${this.absolutePath}`)
2727
}
2828

29+
// Always read files as raw buffers without encoding
30+
// The Base64Encoder works with buffers for both text and binary files
31+
// Using any encoding (like 'utf8') corrupts the data
2932
return fs
30-
.createReadStream(this.absolutePath, { encoding: 'utf8' })
33+
.createReadStream(this.absolutePath)
3134
.pipe(new Base64Encoder())
3235
}
3336

0 commit comments

Comments
 (0)