Uh oh!
There was an error while loading. Please reload this page.
Conversation
jtenner
commented
Aug 22, 2019
@RedDwarfian and @dcodeIO thoughts on this pull request? |
RedDwarfian
commented
Aug 22, 2019
It is not clear in the Naive |
jtenner
commented
Mar 13, 2020
We might like to pull the ASCII encoding pull request first. #27 Otherwise, this is ready for review. |
| if (i32(byteOffset < 0) | i32(byteOffset > buffer.byteLength - length)) throw new RangeError(E_INDEXOUTOFRANGE); | ||
| if (length == 0) return new Buffer(0); | ||
| return assembleBuffer(changetype<usize>(buffer), <usize>byteOffset, <u32>length); |
There was a problem hiding this comment.
@MaxGraey should this be min(length, buffer.byteLength - byteOffset)?
| return assembleBuffer(changetype<usize>(buffer), 0, buffer.byteLength); | ||
| } | ||
| public static fromArray<T extends ArrayBufferView>(value: T, offset: i32 = 0, length: i32 = -1): Buffer { |
There was a problem hiding this comment.
@dcodeIO what is going to happen to this extends clause? Are we going to detach Array from ArrayBufferView?
| // return and retain | ||
| return changetype<Buffer>(result); | ||
| // @ts-ignore: Buffer returns on all valid branches |
There was a problem hiding this comment.
We can suppress this error by returning changetype<Buffer>(null) at the bottom here after the ERROR. What is the right way to do this?
Uh oh!
There was an error while loading. Please reload this page.
Implements
Buffer.from<T>(value: T)and a few other convenience functions.There are lots of obvious problems with not having the function overloads, but there are different paths we can take.
For instance, because there are no optional parameters, we must assume that the default encoding for strings is
UTF8.Things to note about this function:
String[]objects do something complicated: string -> f64 -> u8 to remain compatible with node.Stringobjects need to be converted toUTF8Bufferobjects share their view of the sameArrayBufferArrayBufferobjects are simply attached to a newBufferArrayBufferViewobjects need to convert their values tou8.