Files
scriptc/tests/corpus/text-encode-into-boundaries.ts
Chris Tate 7bcd146c74 Optimize text and byte conversion paths
- Reduce temporary storage and per-byte overhead across Buffer conversions, bounded writes, and text encoding.
- Support runtime Buffer string encodings with consistent defaults, aliases, and catchable errors.
- Cover conversion boundaries, partial writes, malformed inputs, and retained outputs across native and WASI execution.
2026-10-06 09:57:20 -05:00

19 lines
803 B
TypeScript

import { isAscii, isUtf8 } from "node:buffer";
const encoder = new TextEncoder();
for (const source of ["", "abcdefghi", "é", "世", "😀", "abcdefgé世界😀z", "😀abcdefghi", "a\0b"]) {
for (let capacity = 0; capacity <= 24; capacity++) {
const backing = new Uint8Array(28).fill(255);
const destination = backing.subarray(2, 2 + capacity);
const result = encoder.encodeInto(source, destination);
console.log(JSON.stringify(source), capacity, result.read, result.written, Buffer.from(backing).toString("hex"));
}
}
for (let length = 0; length <= 33; length++) {
const bytes = new Uint8Array(length).fill(65);
console.log(length, isAscii(bytes), isUtf8(bytes));
if (length > 0) {
bytes[length - 1] = 128;
console.log(length, isAscii(bytes), isUtf8(bytes));
}
}