Skip to content

Instantly share code, notes, and snippets.

View OMartinez-NeT's full-sized avatar

Oscar Martínez OMartinez-NeT

View GitHub Profile
@OMartinez-NeT
OMartinez-NeT / large-stringify.ts
Last active November 2, 2023 20:56
Stringify large array of objects (over 500 mb) avoid RangeError: Invalid string length
export async function largeStringify<T>(resources: T[]): Promise<Buffer> {
const blobs = [new Blob(["["])];
resources.forEach((resource, index) => {
const resourceString = JSON.stringify(resource);
blobs.push(new Blob([resourceString]));
if (index !== resources.length - 1) {
blobs.push(new Blob([","]));
}
});