diff options
author | nasa <htilcs1115@gmail.com> | 2023-06-08 21:37:19 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-08 06:37:19 -0600 |
commit | 262571e63e3086e0a4ea6125b3836c357a21af86 (patch) | |
tree | 91ef0702d4f24d8484c3c9fc3761049023d0c897 /ext/node/polyfills/_fs | |
parent | 0197f42e6bd77c9bd6f14afd9523c4c252aa099b (diff) |
feat(node_compat): Add a read method to the FileHandle class (#19359)
ref: #19165
The FileHandle class has many missing methods compared to node.
Diffstat (limited to 'ext/node/polyfills/_fs')
-rw-r--r-- | ext/node/polyfills/_fs/_fs_common.ts | 7 | ||||
-rw-r--r-- | ext/node/polyfills/_fs/_fs_read.ts | 14 |
2 files changed, 11 insertions, 10 deletions
diff --git a/ext/node/polyfills/_fs/_fs_common.ts b/ext/node/polyfills/_fs/_fs_common.ts index 19f0d7d17..4e8bfc285 100644 --- a/ext/node/polyfills/_fs/_fs_common.ts +++ b/ext/node/polyfills/_fs/_fs_common.ts @@ -33,6 +33,13 @@ export type BinaryOptionsArgument = | ({ encoding: BinaryEncodings } & FileOptions); export type FileOptionsArgument = Encodings | FileOptions; +export type ReadOptions = { + buffer: Buffer | Uint8Array; + offset: number; + length: number; + position: number | null; +}; + export interface WriteFileOptions extends FileOptions { mode?: number; } diff --git a/ext/node/polyfills/_fs/_fs_read.ts b/ext/node/polyfills/_fs/_fs_read.ts index bce7d334f..2c840f07c 100644 --- a/ext/node/polyfills/_fs/_fs_read.ts +++ b/ext/node/polyfills/_fs/_fs_read.ts @@ -3,6 +3,7 @@ import { Buffer } from "ext:deno_node/buffer.ts"; import { ERR_INVALID_ARG_TYPE } from "ext:deno_node/internal/errors.ts"; import * as io from "ext:deno_io/12_io.js"; import * as fs from "ext:deno_fs/30_fs.js"; +import { ReadOptions } from "ext:deno_node/_fs/_fs_common.ts"; import { validateOffsetLengthRead, validatePosition, @@ -12,13 +13,6 @@ import { validateInteger, } from "ext:deno_node/internal/validators.mjs"; -type readOptions = { - buffer: Buffer | Uint8Array; - offset: number; - length: number; - position: number | null; -}; - type readSyncOptions = { offset: number; length: number; @@ -35,7 +29,7 @@ type Callback = BinaryCallback; export function read(fd: number, callback: Callback): void; export function read( fd: number, - options: readOptions, + options: ReadOptions, callback: Callback, ): void; export function read( @@ -48,7 +42,7 @@ export function read( ): void; export function read( fd: number, - optOrBufferOrCb?: Buffer | Uint8Array | readOptions | Callback, + optOrBufferOrCb?: Buffer | Uint8Array | ReadOptions | Callback, offsetOrCallback?: number | Callback, length?: number, position?: number | null, @@ -86,7 +80,7 @@ export function read( length = buffer.byteLength; position = null; } else { - const opt = optOrBufferOrCb as readOptions; + const opt = optOrBufferOrCb as ReadOptions; if ( !(opt.buffer instanceof Buffer) && !(opt.buffer instanceof Uint8Array) ) { |