perf: prevent stack overflow when concat buffer

This commit is contained in:
Julien Oculi 2024-02-05 15:31:57 +01:00
parent e67050ca65
commit fe316e9dcb
2 changed files with 9 additions and 2 deletions

View file

@ -1,6 +1,6 @@
import { fromFileUrl, join } from '$std/path/mod.ts'
import { builder } from './builder.ts'
import { cssImports, Logger } from './helpers.ts'
import { cssImports, Logger, uInt8ArrayConcat } from './helpers.ts'
export async function bundleCss(
sourceDir: string,
@ -24,7 +24,7 @@ export async function bundleCss(
)
await Deno.writeFile(
join(assetDir, pathname),
Uint8Array.of(...code, ...sourceMappingURL),
uInt8ArrayConcat(code, sourceMappingURL),
)
await Deno.writeFile(

View file

@ -26,3 +26,10 @@ export async function hashFile(file: ArrayBuffer): Promise<string> {
}
export const cssImports: Map<string, string> = new Map()
export function uInt8ArrayConcat(a: Uint8Array, b: Uint8Array) {
const dest = new Uint8Array(a.length + b.length)
dest.set(a)
dest.set(b, a.length)
return dest
}