mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-30 07:14:39 +08:00
- Object.keys(util.types) lists Node's 43 keys in Node's order, and Object.keys over the node:util/types namespace lists them sorted with "default". Object.values and Object.entries over util.types are refused, because some members do not compile yet. - The HTTP server answers 431 Request Header Fields Too Large when a head or trailer block exceeds 1000 fields or the header byte bound, and the trailer block counts its fields on its own, like Node. Parser errors send Node's fixed responses without a Content-Length header. - Server requests start paused like Node's IncomingMessage: body bytes and 'end' wait for a 'data' listener, pipe() or resume(). When the response finishes, an unread request is dumped and emits 'end', before the response's 'close' for an empty body and after it otherwise. A body that is still arriving when the response finishes keeps reaching its listeners. req.complete reads true once the body has arrived. - Document that small Buffers own exact-size ArrayBuffers instead of sharing Node's 64 KiB pool. Corpus 5405-5409 cover each case.
18 lines
1.0 KiB
TypeScript
18 lines
1.0 KiB
TypeScript
// Small Buffers own exact-size ArrayBuffers here, while Node allocates them
|
|
// from a shared 64 KiB pool, so buf.buffer.byteLength and buf.byteOffset
|
|
// differ. Reading a Buffer's window of its ArrayBuffer through byteOffset
|
|
// and length gives the same bytes either way, and Buffer.alloc is never
|
|
// pooled.
|
|
const small = Buffer.from("hello");
|
|
const copy = small.buffer.slice(small.byteOffset, small.byteOffset + small.length);
|
|
console.log(copy.byteLength, new TextDecoder().decode(new Uint8Array(copy)));
|
|
const view = new Uint8Array(small.buffer, small.byteOffset, small.length);
|
|
console.log(Array.from(view).join(","));
|
|
const joined = Buffer.concat([Buffer.from("ab"), Buffer.from("cd")]);
|
|
const data = new DataView(joined.buffer, joined.byteOffset, joined.length);
|
|
console.log(data.getUint16(0), data.byteLength);
|
|
const unsafe = Buffer.allocUnsafe(4).fill(7);
|
|
console.log(Array.from(new Uint8Array(unsafe.buffer, unsafe.byteOffset, 4)).join(","));
|
|
const zeroed = Buffer.alloc(16, 1);
|
|
console.log(zeroed.buffer.byteLength, zeroed.byteOffset);
|