diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-08-14 09:42:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 09:42:31 -0700 |
commit | 1f2d48cd975b719f0248e471f3b503cb01398dfb (patch) | |
tree | f9ac89ff011566aad45456e6d49e2802ce6f345b /ext/node/polyfills/_fs/_fs_write.mjs | |
parent | c765d9ad2fbd82be1b025cae3930fdfe8e30f9e2 (diff) |
fix(node/fs): node:fs.read and write should accept typed arrays other than Uint8Array (#25030)
Part of #25028.
Our underlying read/write operations in `io` assume the buffer is a
Uint8Array, but we were passing in other typed arrays (in the case above
it was `Int8Array`).
Diffstat (limited to 'ext/node/polyfills/_fs/_fs_write.mjs')
-rw-r--r-- | ext/node/polyfills/_fs/_fs_write.mjs | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/ext/node/polyfills/_fs/_fs_write.mjs b/ext/node/polyfills/_fs/_fs_write.mjs index c0ae129d3..b4b133222 100644 --- a/ext/node/polyfills/_fs/_fs_write.mjs +++ b/ext/node/polyfills/_fs/_fs_write.mjs @@ -12,6 +12,7 @@ import { import * as io from "ext:deno_io/12_io.js"; import * as fs from "ext:deno_fs/30_fs.js"; import { + arrayBufferViewToUint8Array, getValidatedFd, validateOffsetLengthWrite, validateStringAfterArrayBufferView, @@ -23,9 +24,7 @@ export function writeSync(fd, buffer, offset, length, position) { fd = getValidatedFd(fd); const innerWriteSync = (fd, buffer, offset, length, position) => { - if (buffer instanceof DataView) { - buffer = new Uint8Array(buffer.buffer); - } + buffer = arrayBufferViewToUint8Array(buffer); if (typeof position === "number") { fs.seekSync(fd, position, io.SeekMode.Start); } @@ -69,9 +68,7 @@ export function write(fd, buffer, offset, length, position, callback) { fd = getValidatedFd(fd); const innerWrite = async (fd, buffer, offset, length, position) => { - if (buffer instanceof DataView) { - buffer = new Uint8Array(buffer.buffer); - } + buffer = arrayBufferViewToUint8Array(buffer); if (typeof position === "number") { await fs.seek(fd, position, io.SeekMode.Start); } |