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:
@@ -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==");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user