-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Observe the test case:
Lines 12 to 21 in 5c64632
function getCorrectBuffer(content) | |
{ | |
const arrayBuffer = new ArrayBuffer(content.length); | |
const uint8Array = new Uint8Array(arrayBuffer); | |
for(let i = 0; i < content.length; i++) | |
uint8Array[i] = content[i]; | |
return arrayBuffer.slice(0); | |
} |
The file being read is copied into a new ArrayBuffer (line 17), which is in turn copied to a new one (line 20 with slice()
Returns a new ArrayBuffer whose contents are a copy of this ArrayBuffer).
Why the same data has to be copied 2 times? If the underlying data is 1GB, that is 2GB additonal memory being used (although the intermediary 1GB will be released once the function ends). Just curious.
P.S. in our applications we tried to feed the Buffer returnd directly from ReadFileSync or the ArrayBuffer of that Buffer, all failed with this error. The only way that works is to honestly copy 2 times just like you did.
throw new Error("Object's schema was not verified against input data for MyModule");
^
Can you fix this issue by adding a line of comment before the line 12 reasoning the 2× copying?