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/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()) } 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() }