1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00

BREAKING(fs): remove Deno.seek[Sync]() (#25449)

Towards #22079
This commit is contained in:
Asher Gomez 2024-09-05 20:37:28 +10:00 committed by GitHub
parent b01578ae1f
commit c73b4a0877
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 26 additions and 162 deletions

View file

@ -338,7 +338,7 @@ pub const OP_DETAILS: phf::Map<&'static str, [&'static str; 2]> = phf_map! {
"op_fs_realpath_async" => ["resolve a path", "awaiting the result of a `Deno.realpath` call"],
"op_fs_remove_async" => ["remove a file or directory", "awaiting the result of a `Deno.remove` call"],
"op_fs_rename_async" => ["rename a file or directory", "awaiting the result of a `Deno.rename` call"],
"op_fs_seek_async" => ["seek in a file", "awaiting the result of a `Deno.seek` or `Deno.FsFile.seek` call"],
"op_fs_seek_async" => ["seek in a file", "awaiting the result of a `Deno.FsFile.prototype.seek` call"],
"op_fs_stat_async" => ["get file metadata", "awaiting the result of a `Deno.stat` call"],
"op_fs_symlink_async" => ["create a symlink", "awaiting the result of a `Deno.symlink` call"],
"op_fs_truncate_async" => ["truncate a file", "awaiting the result of a `Deno.truncate` call"],

View file

@ -1920,104 +1920,6 @@ declare namespace Deno {
*/
export function createSync(path: string | URL): FsFile;
/** Seek a resource ID (`rid`) to the given `offset` under mode given by `whence`.
* The call resolves to the new position within the resource (bytes from the start).
*
* ```ts
* // Given file.rid pointing to file with "Hello world", which is 11 bytes long:
* using file = await Deno.open(
* "hello.txt",
* { read: true, write: true, truncate: true, create: true },
* );
* await file.write(new TextEncoder().encode("Hello world"));
*
* // advance cursor 6 bytes
* const cursorPosition = await Deno.seek(file.rid, 6, Deno.SeekMode.Start);
* console.log(cursorPosition); // 6
* const buf = new Uint8Array(100);
* await file.read(buf);
* console.log(new TextDecoder().decode(buf)); // "world"
* ```
*
* The seek modes work as follows:
*
* ```ts
* // Given file.rid pointing to file with "Hello world", which is 11 bytes long:
* using file = await Deno.open(
* "hello.txt",
* { read: true, write: true, truncate: true, create: true },
* );
* await file.write(new TextEncoder().encode("Hello world"));
*
* // Seek 6 bytes from the start of the file
* console.log(await Deno.seek(file.rid, 6, Deno.SeekMode.Start)); // "6"
* // Seek 2 more bytes from the current position
* console.log(await Deno.seek(file.rid, 2, Deno.SeekMode.Current)); // "8"
* // Seek backwards 2 bytes from the end of the file
* console.log(await Deno.seek(file.rid, -2, Deno.SeekMode.End)); // "9" (i.e. 11-2)
* ```
*
* @deprecated This will be removed in Deno 2.0. See the
* {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide}
* for migration instructions.
*
* @category I/O
*/
export function seek(
rid: number,
offset: number | bigint,
whence: SeekMode,
): Promise<number>;
/** Synchronously seek a resource ID (`rid`) to the given `offset` under mode
* given by `whence`. The new position within the resource (bytes from the
* start) is returned.
*
* ```ts
* using file = Deno.openSync(
* "hello.txt",
* { read: true, write: true, truncate: true, create: true },
* );
* file.writeSync(new TextEncoder().encode("Hello world"));
*
* // advance cursor 6 bytes
* const cursorPosition = Deno.seekSync(file.rid, 6, Deno.SeekMode.Start);
* console.log(cursorPosition); // 6
* const buf = new Uint8Array(100);
* file.readSync(buf);
* console.log(new TextDecoder().decode(buf)); // "world"
* ```
*
* The seek modes work as follows:
*
* ```ts
* // Given file.rid pointing to file with "Hello world", which is 11 bytes long:
* using file = Deno.openSync(
* "hello.txt",
* { read: true, write: true, truncate: true, create: true },
* );
* file.writeSync(new TextEncoder().encode("Hello world"));
*
* // Seek 6 bytes from the start of the file
* console.log(Deno.seekSync(file.rid, 6, Deno.SeekMode.Start)); // "6"
* // Seek 2 more bytes from the current position
* console.log(Deno.seekSync(file.rid, 2, Deno.SeekMode.Current)); // "8"
* // Seek backwards 2 bytes from the end of the file
* console.log(Deno.seekSync(file.rid, -2, Deno.SeekMode.End)); // "9" (i.e. 11-2)
* ```
*
* @deprecated This will be removed in Deno 2.0. See the
* {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide}
* for migration instructions.
*
* @category I/O
*/
export function seekSync(
rid: number,
offset: number | bigint,
whence: SeekMode,
): number;
/**
* Flushes any pending data and metadata operations of the given file stream
* to disk.

View file

@ -543,22 +543,6 @@ async function funlock(rid) {
await op_fs_funlock_async_unstable(rid);
}
function seekSync(
rid,
offset,
whence,
) {
return op_fs_seek_sync(rid, offset, whence);
}
function seek(
rid,
offset,
whence,
) {
return op_fs_seek_async(rid, offset, whence);
}
function openSync(
path,
options,
@ -663,11 +647,11 @@ class FsFile {
}
seek(offset, whence) {
return seek(this.#rid, offset, whence);
return op_fs_seek_async(this.#rid, offset, whence);
}
seekSync(offset, whence) {
return seekSync(this.#rid, offset, whence);
return op_fs_seek_sync(this.#rid, offset, whence);
}
async stat() {
@ -979,8 +963,6 @@ export {
removeSync,
rename,
renameSync,
seek,
seekSync,
stat,
statSync,
symlink,

View file

@ -6,7 +6,6 @@
import { Buffer } from "node:buffer";
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 {
arrayBufferViewToUint8Array,
@ -18,6 +17,7 @@ import {
validateInteger,
} from "ext:deno_node/internal/validators.mjs";
import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts";
import { op_fs_seek_async, op_fs_seek_sync } from "ext:core/ops";
type readSyncOptions = {
offset: number;
@ -119,15 +119,19 @@ export function read(
try {
let nread: number | null;
if (typeof position === "number" && position >= 0) {
const currentPosition = await fs.seek(fd, 0, io.SeekMode.Current);
const currentPosition = await op_fs_seek_async(
fd,
0,
io.SeekMode.Current,
);
// We use sync calls below to avoid being affected by others during
// these calls.
fs.seekSync(fd, position, io.SeekMode.Start);
op_fs_seek_sync(fd, position, io.SeekMode.Start);
nread = io.readSync(
fd,
arrayBufferViewToUint8Array(buffer).subarray(offset, offset + length),
);
fs.seekSync(fd, currentPosition, io.SeekMode.Start);
op_fs_seek_sync(fd, currentPosition, io.SeekMode.Start);
} else {
nread = await io.read(
fd,
@ -191,8 +195,8 @@ export function readSync(
let currentPosition = 0;
if (typeof position === "number" && position >= 0) {
currentPosition = fs.seekSync(fd, 0, io.SeekMode.Current);
fs.seekSync(fd, position, io.SeekMode.Start);
currentPosition = op_fs_seek_sync(fd, 0, io.SeekMode.Current);
op_fs_seek_sync(fd, position, io.SeekMode.Start);
}
const numberOfBytesRead = io.readSync(
@ -201,7 +205,7 @@ export function readSync(
);
if (typeof position === "number" && position >= 0) {
fs.seekSync(fd, currentPosition, io.SeekMode.Start);
op_fs_seek_sync(fd, currentPosition, io.SeekMode.Start);
}
return numberOfBytesRead ?? 0;

View file

@ -14,7 +14,7 @@ import {
import { maybeCallback } from "ext:deno_node/_fs/_fs_common.ts";
import { 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 { op_fs_seek_async, op_fs_seek_sync } from "ext:core/ops";
type Callback = (
err: ErrnoException | null,
@ -56,7 +56,7 @@ export function readv(
position: number | null,
) => {
if (typeof position === "number") {
await fs.seek(fd, position, io.SeekMode.Start);
await op_fs_seek_async(fd, position, io.SeekMode.Start);
}
let readTotal = 0;
@ -104,7 +104,7 @@ export function readvSync(
}
if (typeof position === "number") {
validateInteger(position, "position", 0);
fs.seekSync(fd, position, io.SeekMode.Start);
op_fs_seek_sync(fd, position, io.SeekMode.Start);
}
let readTotal = 0;

View file

@ -10,7 +10,6 @@ import {
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 {
arrayBufferViewToUint8Array,
getValidatedFd,
@ -19,6 +18,7 @@ import {
} from "ext:deno_node/internal/fs/utils.mjs";
import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts";
import { maybeCallback } from "ext:deno_node/_fs/_fs_common.ts";
import { op_fs_seek_async, op_fs_seek_sync } from "ext:core/ops";
export function writeSync(fd, buffer, offset, length, position) {
fd = getValidatedFd(fd);
@ -26,7 +26,7 @@ export function writeSync(fd, buffer, offset, length, position) {
const innerWriteSync = (fd, buffer, offset, length, position) => {
buffer = arrayBufferViewToUint8Array(buffer);
if (typeof position === "number") {
fs.seekSync(fd, position, io.SeekMode.Start);
op_fs_seek_sync(fd, position, io.SeekMode.Start);
}
let currentOffset = offset;
const end = offset + length;
@ -70,7 +70,7 @@ export function write(fd, buffer, offset, length, position, callback) {
const innerWrite = async (fd, buffer, offset, length, position) => {
buffer = arrayBufferViewToUint8Array(buffer);
if (typeof position === "number") {
await fs.seek(fd, position, io.SeekMode.Start);
await op_fs_seek_async(fd, position, io.SeekMode.Start);
}
let currentOffset = offset;
const end = offset + length;

View file

@ -9,7 +9,7 @@ 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";
import { op_fs_seek_async, op_fs_seek_sync } from "ext:core/ops";
export function writev(fd, buffers, position, callback) {
const innerWritev = async (fd, buffers, position) => {
@ -23,7 +23,7 @@ export function writev(fd, buffers, position, callback) {
}
}
if (typeof position === "number") {
await fs.seekSync(fd, position, io.SeekMode.Start);
await op_fs_seek_async(fd, position, io.SeekMode.Start);
}
const buffer = Buffer.concat(chunks);
let currentOffset = 0;
@ -64,7 +64,7 @@ export function writevSync(fd, buffers, position) {
}
}
if (typeof position === "number") {
fs.seekSync(fd, position, io.SeekMode.Start);
op_fs_seek_sync(fd, position, io.SeekMode.Start);
}
const buffer = Buffer.concat(chunks);
let currentOffset = 0;

View file

@ -30,7 +30,7 @@
import { assert } from "ext:deno_node/_util/asserts.ts";
import * as io from "ext:deno_io/12_io.js";
import * as fs from "ext:deno_fs/30_fs.js";
import { op_fs_seek_sync } from "ext:core/ops";
/**
* Write to the given file from the given buffer synchronously.
@ -63,7 +63,7 @@ export function writeBuffer(
);
if (position) {
fs.seekSync(fd, position, io.SeekMode.Current);
op_fs_seek_sync(fd, position, io.SeekMode.Current);
}
const subarray = buffer.subarray(offset, offset + length);

View file

@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { core, internals } from "ext:core/mod.js";
import { core } from "ext:core/mod.js";
import {
op_net_listen_udp,
op_net_listen_unixpacket,
@ -96,22 +96,6 @@ const denoNs = {
stdin: io.stdin,
stdout: io.stdout,
stderr: io.stderr,
seek(rid, offset, whence) {
internals.warnOnDeprecatedApi(
"Deno.seek()",
new Error().stack,
"Use `file.seek()` instead.",
);
return fs.seek(rid, offset, whence);
},
seekSync(rid, offset, whence) {
internals.warnOnDeprecatedApi(
"Deno.seekSync()",
new Error().stack,
"Use `file.seekSync()` instead.",
);
return fs.seekSync(rid, offset, whence);
},
connect: net.connect,
listen: net.listen,
loadavg: os.loadavg,

View file

@ -804,8 +804,6 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
delete Deno.FsFile.prototype.rid;
delete Deno.funlock;
delete Deno.funlockSync;
delete Deno.seek;
delete Deno.seekSync;
}
} else {
// Warmup
@ -967,8 +965,6 @@ function bootstrapWorkerRuntime(
delete Deno.FsFile.prototype.rid;
delete Deno.funlock;
delete Deno.funlockSync;
delete Deno.seek;
delete Deno.seekSync;
}
} else {
// Warmup

View file

@ -6,8 +6,6 @@ console.log(
);
console.log("Deno.funlock is", Deno.funlock);
console.log("Deno.funlockSync is", Deno.funlockSync);
console.log("Deno.seek is", Deno.seek);
console.log("Deno.seekSync is", Deno.seekSync);
// TCP
// Since these tests may run in parallel, ensure this port is unique to this file

View file

@ -3,8 +3,6 @@ Deno.Buffer is undefined
Deno.FsFile.prototype.rid is undefined
Deno.funlock is undefined
Deno.funlockSync is undefined
Deno.seek is undefined
Deno.seekSync is undefined
Deno.Listener.prototype.rid is undefined
Deno.Conn.prototype.rid is undefined
Deno.UnixConn.prototype.rid is undefined