feat(coding-agent): added Buffer.toBase64() polyfill for Bun compatibility

- Added Buffer.toBase64() polyfill for Bun compatibility to enable base64 encoding of buffers.
- Added test coverage for Buffer.toBase64() polyfill to verify base64 encoding functionality.
This commit is contained in:
can1357
2026-02-21 22:59:04 +01:00
parent 401b4f48d9
commit 1932e175f5
3 changed files with 22 additions and 0 deletions
+3
View File
@@ -1,6 +1,9 @@
# Changelog
## [Unreleased]
### Added
- Added Buffer.toBase64() polyfill for Bun compatibility to enable base64 encoding of buffers
## [12.18.0] - 2026-02-21
@@ -37,6 +37,11 @@ function pickSmaller(
return a.buffer.length <= b.buffer.length ? a : b;
}
/** Polyfill for Buffer.toBase64, technically since it derives from Uint8Array it should exist but Bun reasons... */
Buffer.prototype.toBase64 = function (this: Buffer) {
return new Uint8Array(this.buffer, this.byteOffset, this.byteLength).toBase64();
};
/**
* Resize an image to fit within the specified max dimensions and file size.
* Returns the original image if it already fits within the limits.
@@ -0,0 +1,14 @@
import { describe, expect, it } from "bun:test";
describe("Buffer.toBase64", async () => {
await import("../src/utils/image-resize");
it("should be defined", () => {
expect(Buffer.prototype.toBase64).toBeDefined();
});
it("should return a base64 string", () => {
const buffer = Buffer.from("Hello, world!");
expect(buffer.toBase64()).toBe("SGVsbG8sIHdvcmxkIQ==");
});
});