diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-05-26 16:18:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-26 16:18:27 +0200 |
commit | a11681a9b02f2f4a0f2bf6945a44b2937c6a9af1 (patch) | |
tree | 55b3a63959b2a935a86c30d8282fbe294f2bb892 /ext/node/polyfills/_fs/_fs_read.ts | |
parent | d72e0281ff41a87c32aefd0876bace23470a4dc5 (diff) |
refactor(node): use internal io and fs APIs (#19267)
Diffstat (limited to 'ext/node/polyfills/_fs/_fs_read.ts')
-rw-r--r-- | ext/node/polyfills/_fs/_fs_read.ts | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/ext/node/polyfills/_fs/_fs_read.ts b/ext/node/polyfills/_fs/_fs_read.ts index b34384dd4..bce7d334f 100644 --- a/ext/node/polyfills/_fs/_fs_read.ts +++ b/ext/node/polyfills/_fs/_fs_read.ts @@ -1,6 +1,8 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. 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 { validateOffsetLengthRead, validatePosition, @@ -117,14 +119,14 @@ export function read( try { let nread: number | null; if (typeof position === "number" && position >= 0) { - const currentPosition = await Deno.seek(fd, 0, Deno.SeekMode.Current); + const currentPosition = await fs.seek(fd, 0, io.SeekMode.Current); // We use sync calls below to avoid being affected by others during // these calls. - Deno.seekSync(fd, position, Deno.SeekMode.Start); - nread = Deno.readSync(fd, buffer); - Deno.seekSync(fd, currentPosition, Deno.SeekMode.Start); + fs.seekSync(fd, position, io.SeekMode.Start); + nread = io.readSync(fd, buffer); + fs.seekSync(fd, currentPosition, io.SeekMode.Start); } else { - nread = await Deno.read(fd, buffer); + nread = await io.read(fd, buffer); } cb(null, nread ?? 0, Buffer.from(buffer.buffer, offset, length)); } catch (error) { @@ -183,14 +185,14 @@ export function readSync( let currentPosition = 0; if (typeof position === "number" && position >= 0) { - currentPosition = Deno.seekSync(fd, 0, Deno.SeekMode.Current); - Deno.seekSync(fd, position, Deno.SeekMode.Start); + currentPosition = fs.seekSync(fd, 0, io.SeekMode.Current); + fs.seekSync(fd, position, io.SeekMode.Start); } - const numberOfBytesRead = Deno.readSync(fd, buffer); + const numberOfBytesRead = io.readSync(fd, buffer); if (typeof position === "number" && position >= 0) { - Deno.seekSync(fd, currentPosition, Deno.SeekMode.Start); + fs.seekSync(fd, currentPosition, io.SeekMode.Start); } return numberOfBytesRead ?? 0; |