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/internal | |
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/internal')
-rw-r--r-- | ext/node/polyfills/internal/fs/utils.mjs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/ext/node/polyfills/internal/fs/utils.mjs b/ext/node/polyfills/internal/fs/utils.mjs index 9f3322bae..53184b9c3 100644 --- a/ext/node/polyfills/internal/fs/utils.mjs +++ b/ext/node/polyfills/internal/fs/utils.mjs @@ -986,6 +986,16 @@ export const validatePosition = hideStackFrames((position) => { } }); +/** @type {(buffer: ArrayBufferView) => Uint8Array} */ +export const arrayBufferViewToUint8Array = hideStackFrames( + (buffer) => { + if (!(buffer instanceof Uint8Array)) { + return new Uint8Array(buffer.buffer); + } + return buffer; + }, +); + export const realpathCacheKey = Symbol("realpathCacheKey"); export const constants = { kIoMaxLength, |