Repository navigation
Conversation
Writing a Uint8Array, or any ArrayBufferView that is not a Buffer, to a file in a memory or ZIP mount threw "data.copy is not a function". This hit fs.writeFileSync(), fs.appendFileSync(), fs.promises.writeFile() and fs.writeSync() alike, so writing the output of TextEncoder failed, while the same calls work on a real file. The memory and ZIP file handles called Buffer methods on the data they were given. View the data's bytes as a Buffer before copying it, and count lengths in bytes, so that offset and length mean bytes for multi-byte views such as Uint16Array too, as they do in node:fs. Assisted-by: a closed-source coding agent Signed-off-by: Raunak Burrows <raunakburrows@gmail.com>
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. Caution AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context. |
writing a
Uint8Array(or anyArrayBufferViewthat isn't aBuffer) to a file in a memory or zip vfs mount throwsTypeError: data.copy is not a function. sofs.writeFileSync(file, new TextEncoder().encode('hi')),fs.promises.writeFile,fs.appendFileSyncandfs.writeSyncwith a typed array all fail inside a mount, while they work on a real file.the memory and zip file handles call
Buffermethods (copy) on whatever they're given. this views the data's bytes as aBufferbefore copying, and usesbyteLengthinstead oflength, so offset/length count bytes forUint16Array& co. like they do innode:fs. before this, the zip handle'swriteFileSyncwrote one byte per element of aUint16Array, andfilehandle.appendFile()wrote only the first half of one.evidence.mp4
tests: added a case to
test/parallel/test-vfs-handle-semantics.js(runs on the memory and zip providers):writeFileSyncwith aUint8Array,fs.promises.appendFilewith aUint8Array,appendFileSyncwith aDataView,writeSyncwith aUint16Array+ byte offset/length,filehandle.appendFilewith aUint16Array. both cases fail on main and pass here.python3 tools/test.py 'parallel/test-vfs-*' parallel/test-fs-write-file-sync parallel/test-fs-append-file-sync parallel/test-fs-write-sync: 131/131 pass. eslint clean on the touched files.ai disclosure: i used an AI coding agent to find this, write the fix and the test. i read the diff, checked it against
node:fs's handling ofArrayBufferViewwrites, and ran the test and the repro above on a local build before opening this.