mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
* Faster, safer `Buffer.concat` * Use wrappers when creating `Buffer` in C++ * Bun.concatArrayBuffers small optimization * Add comment * Add tests * Ignore empty buffers * Add assertion * Update buffer-concat.mjs * Update buffer-concat.mjs --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
22 lines
664 B
TypeScript
22 lines
664 B
TypeScript
import { test, expect } from "bun:test";
|
|
|
|
test("Buffer.concat throws OutOfMemoryError", () => {
|
|
const bufferToUse = Buffer.allocUnsafe(1024 * 1024 * 64);
|
|
const buffers = new Array(1024);
|
|
for (let i = 0; i < buffers.length; i++) {
|
|
buffers[i] = bufferToUse;
|
|
}
|
|
|
|
expect(() => Buffer.concat(buffers)).toThrow(/out of memory/i);
|
|
});
|
|
|
|
test("Bun.concatArrayBuffers throws OutOfMemoryError", () => {
|
|
const bufferToUse = Buffer.allocUnsafe(1024 * 1024 * 64);
|
|
const buffers = new Array(1024);
|
|
for (let i = 0; i < buffers.length; i++) {
|
|
buffers[i] = bufferToUse;
|
|
}
|
|
|
|
expect(() => Bun.concatArrayBuffers(buffers)).toThrow(/Failed to allocate/i);
|
|
});
|