From d2f2197cbb7d1a52330b7014beec655b66fb207b Mon Sep 17 00:00:00 2001 From: Joris Conijn Date: Thu, 12 Feb 2026 09:13:58 +0100 Subject: [PATCH 1/2] 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) --- src/blob.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/blob.ts b/src/blob.ts index b6d598b..930dd5b 100644 --- a/src/blob.ts +++ b/src/blob.ts @@ -26,8 +26,11 @@ export class Blob { throw new Error(`File does not exist, path: ${this.absolutePath}`) } + // Always read files as raw buffers without encoding + // The Base64Encoder works with buffers for both text and binary files + // Using any encoding (like 'utf8') corrupts the data return fs - .createReadStream(this.absolutePath, { encoding: 'utf8' }) + .createReadStream(this.absolutePath) .pipe(new Base64Encoder()) } From 1374e437b676dca7d22c80daa01e66a9c138345a Mon Sep 17 00:00:00 2001 From: Joris Conijn Date: Thu, 12 Feb 2026 09:38:24 +0100 Subject: [PATCH 2/2] fix: prevent binary file corruption when encoding to base64 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 --- .gitignore | 1 + dist/index.js | 9 ++++++--- src/stream/base64-encoder.ts | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index e8e984a..45879b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .envrc +.idea/ # Logs logs diff --git a/dist/index.js b/dist/index.js index c12df09..5103055 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29884,8 +29884,11 @@ class Blob { if (!fs.existsSync(this.absolutePath)) { throw new Error(`File does not exist, path: ${this.absolutePath}`); } + // Always read files as raw buffers without encoding + // The Base64Encoder works with buffers for both text and binary files + // Using any encoding (like 'utf8') corrupts the data return fs - .createReadStream(this.absolutePath, { encoding: 'utf8' }) + .createReadStream(this.absolutePath) .pipe(new base64_encoder_1.default()); } load() { @@ -30591,12 +30594,12 @@ class Base64Encoder extends node_stream_1.Transform { chunk = chunk.subarray(0, chunk.length - overflowSize); } const base64String = chunk.toString('base64'); - this.push(node_buffer_1.Buffer.from(base64String)); + this.push(base64String); callback(); } _flush(callback) { if (this.overflow) { - this.push(node_buffer_1.Buffer.from(this.overflow.toString('base64'))); + this.push(this.overflow.toString('base64')); } callback(); } diff --git a/src/stream/base64-encoder.ts b/src/stream/base64-encoder.ts index 671f87e..d8e4e2a 100644 --- a/src/stream/base64-encoder.ts +++ b/src/stream/base64-encoder.ts @@ -25,13 +25,13 @@ export default class Base64Encoder extends Transform { } const base64String = chunk.toString('base64') - this.push(Buffer.from(base64String)) + this.push(base64String) callback() } _flush(callback: TransformCallback): void { if (this.overflow) { - this.push(Buffer.from(this.overflow.toString('base64'))) + this.push(this.overflow.toString('base64')) } callback() }