Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.envrc
.idea/

# Logs
logs
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 4 additions & 1 deletion src/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
4 changes: 2 additions & 2 deletions src/stream/base64-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down