fix(std/node): Add ascii support for Buffer#8948
Conversation
| ]; | ||
|
|
||
| function decodeAscii(buffer: Uint8Array) { | ||
| return Array.from(buffer).map((byte) => String.fromCharCode(byte & 0x7F)).join(""); |
There was a problem hiding this comment.
Any reason this these aren't done with TextEncoder / TextDecoder ?
There was a problem hiding this comment.
Or encoding/ascii directly if that's an issue
There was a problem hiding this comment.
AFAIK TextEncoder is UTF8 only
There was a problem hiding this comment.
What about encoding/ascii in deno's code? I'm pretty sure Deno has ASCII encoding/decoding support (I vaguely recall using it)
|
|
||
| function encodeAscii(text: string) { | ||
| return new Uint8Array( | ||
| Object.keys(text).map((i) => text.charCodeAt(Number(i))), |
There was a problem hiding this comment.
If performance matters here: there's probably a steep performance cliff for longer strings.
V8 has a small-numbers-as-strings cache that's not effective for longer strings and I doubt V8 can figure out it doesn't actually need to materialize the indexes as strings.
| start = start < 0 ? 0 : start; | ||
| end = end > this.length ? this.length : end; |
There was a problem hiding this comment.
Don't know if it matters but these let through NaNs.
|
Deno standard library was moved to denoland/deno_std, please reopen your PR there. |
Towards merging nodejs/readable-stream#452