summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/_fs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/polyfills/_fs')
-rw-r--r--ext/node/polyfills/_fs/_fs_read.ts20
-rw-r--r--ext/node/polyfills/_fs/_fs_write.mjs10
-rw-r--r--ext/node/polyfills/_fs/_fs_writev.mjs10
3 files changed, 23 insertions, 17 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;
diff --git a/ext/node/polyfills/_fs/_fs_write.mjs b/ext/node/polyfills/_fs/_fs_write.mjs
index bd0ffd105..fd7a1171c 100644
--- a/ext/node/polyfills/_fs/_fs_write.mjs
+++ b/ext/node/polyfills/_fs/_fs_write.mjs
@@ -2,6 +2,8 @@
// Copyright Joyent, Inc. and Node.js contributors. All rights reserved. MIT license.
import { Buffer } from "ext:deno_node/buffer.ts";
import { validateEncoding, validateInteger } from "ext:deno_node/internal/validators.mjs";
+import * as io from "ext:deno_io/12_io.js";
+import * as fs from "ext:deno_fs/30_fs.js";
import {
getValidatedFd,
showStringCoercionDeprecation,
@@ -19,12 +21,12 @@ export function writeSync(fd, buffer, offset, length, position) {
buffer = new Uint8Array(buffer.buffer);
}
if (typeof position === "number") {
- Deno.seekSync(fd, position, Deno.SeekMode.Start);
+ fs.seekSync(fd, position, io.SeekMode.Start);
}
let currentOffset = offset;
const end = offset + length;
while (currentOffset - offset < length) {
- currentOffset += Deno.writeSync(fd, buffer.subarray(currentOffset, end));
+ currentOffset += io.writeSync(fd, buffer.subarray(currentOffset, end));
}
return currentOffset - offset;
};
@@ -65,12 +67,12 @@ export function write(fd, buffer, offset, length, position, callback) {
buffer = new Uint8Array(buffer.buffer);
}
if (typeof position === "number") {
- await Deno.seek(fd, position, Deno.SeekMode.Start);
+ await fs.seek(fd, position, io.SeekMode.Start);
}
let currentOffset = offset;
const end = offset + length;
while (currentOffset - offset < length) {
- currentOffset += await Deno.write(
+ currentOffset += await io.write(
fd,
buffer.subarray(currentOffset, end),
);
diff --git a/ext/node/polyfills/_fs/_fs_writev.mjs b/ext/node/polyfills/_fs/_fs_writev.mjs
index 7440f4fd7..84e2b7cdd 100644
--- a/ext/node/polyfills/_fs/_fs_writev.mjs
+++ b/ext/node/polyfills/_fs/_fs_writev.mjs
@@ -4,6 +4,8 @@ import { Buffer } from "ext:deno_node/buffer.ts";
import { validateBufferArray } from "ext:deno_node/internal/fs/utils.mjs";
import { getValidatedFd } from "ext:deno_node/internal/fs/utils.mjs";
import { maybeCallback } from "ext:deno_node/_fs/_fs_common.ts";
+import * as io from "ext:deno_io/12_io.js";
+import * as fs from "ext:deno_fs/30_fs.js";
export function writev(fd, buffers, position, callback) {
const innerWritev = async (fd, buffers, position) => {
@@ -17,12 +19,12 @@ export function writev(fd, buffers, position, callback) {
}
}
if (typeof position === "number") {
- await Deno.seekSync(fd, position, Deno.SeekMode.Start);
+ await fs.seekSync(fd, position, io.SeekMode.Start);
}
const buffer = Buffer.concat(chunks);
let currentOffset = 0;
while (currentOffset < buffer.byteLength) {
- currentOffset += await Deno.writeSync(fd, buffer.subarray(currentOffset));
+ currentOffset += await io.writeSync(fd, buffer.subarray(currentOffset));
}
return currentOffset - offset;
};
@@ -58,12 +60,12 @@ export function writevSync(fd, buffers, position) {
}
}
if (typeof position === "number") {
- Deno.seekSync(fd, position, Deno.SeekMode.Start);
+ fs.seekSync(fd, position, io.SeekMode.Start);
}
const buffer = Buffer.concat(chunks);
let currentOffset = 0;
while (currentOffset < buffer.byteLength) {
- currentOffset += Deno.writeSync(fd, buffer.subarray(currentOffset));
+ currentOffset += io.writeSync(fd, buffer.subarray(currentOffset));
}
return currentOffset - offset;
};