mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
feat: Add Deno.FsFile, deprecate Deno.File (#13660)
This commit is contained in:
parent
bdc8006a36
commit
9b5e336c3d
4 changed files with 47 additions and 16 deletions
45
cli/dts/lib.deno.ns.d.ts
vendored
45
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -795,7 +795,7 @@ declare namespace Deno {
|
||||||
},
|
},
|
||||||
): IterableIterator<Uint8Array>;
|
): IterableIterator<Uint8Array>;
|
||||||
|
|
||||||
/** Synchronously open a file and return an instance of `Deno.File`. The
|
/** Synchronously open a file and return an instance of `Deno.FsFile`. The
|
||||||
* file does not need to previously exist if using the `create` or `createNew`
|
* file does not need to previously exist if using the `create` or `createNew`
|
||||||
* open options. It is the callers responsibility to close the file when finished
|
* open options. It is the callers responsibility to close the file when finished
|
||||||
* with it.
|
* with it.
|
||||||
|
@ -808,9 +808,9 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and/or `allow-write` permissions depending on options.
|
* Requires `allow-read` and/or `allow-write` permissions depending on options.
|
||||||
*/
|
*/
|
||||||
export function openSync(path: string | URL, options?: OpenOptions): File;
|
export function openSync(path: string | URL, options?: OpenOptions): FsFile;
|
||||||
|
|
||||||
/** Open a file and resolve to an instance of `Deno.File`. The
|
/** Open a file and resolve to an instance of `Deno.FsFile`. The
|
||||||
* file does not need to previously exist if using the `create` or `createNew`
|
* file does not need to previously exist if using the `create` or `createNew`
|
||||||
* open options. It is the callers responsibility to close the file when finished
|
* open options. It is the callers responsibility to close the file when finished
|
||||||
* with it.
|
* with it.
|
||||||
|
@ -826,10 +826,10 @@ declare namespace Deno {
|
||||||
export function open(
|
export function open(
|
||||||
path: string | URL,
|
path: string | URL,
|
||||||
options?: OpenOptions,
|
options?: OpenOptions,
|
||||||
): Promise<File>;
|
): Promise<FsFile>;
|
||||||
|
|
||||||
/** Creates a file if none exists or truncates an existing file and returns
|
/** Creates a file if none exists or truncates an existing file and returns
|
||||||
* an instance of `Deno.File`.
|
* an instance of `Deno.FsFile`.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* const file = Deno.createSync("/foo/bar.txt");
|
* const file = Deno.createSync("/foo/bar.txt");
|
||||||
|
@ -837,10 +837,10 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions.
|
* Requires `allow-read` and `allow-write` permissions.
|
||||||
*/
|
*/
|
||||||
export function createSync(path: string | URL): File;
|
export function createSync(path: string | URL): FsFile;
|
||||||
|
|
||||||
/** Creates a file if none exists or truncates an existing file and resolves to
|
/** Creates a file if none exists or truncates an existing file and resolves to
|
||||||
* an instance of `Deno.File`.
|
* an instance of `Deno.FsFile`.
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* const file = await Deno.create("/foo/bar.txt");
|
* const file = await Deno.create("/foo/bar.txt");
|
||||||
|
@ -848,7 +848,7 @@ declare namespace Deno {
|
||||||
*
|
*
|
||||||
* Requires `allow-read` and `allow-write` permissions.
|
* Requires `allow-read` and `allow-write` permissions.
|
||||||
*/
|
*/
|
||||||
export function create(path: string | URL): Promise<File>;
|
export function create(path: string | URL): Promise<FsFile>;
|
||||||
|
|
||||||
/** Synchronously read from a resource ID (`rid`) into an array buffer (`buffer`).
|
/** Synchronously read from a resource ID (`rid`) into an array buffer (`buffer`).
|
||||||
*
|
*
|
||||||
|
@ -1070,6 +1070,35 @@ declare namespace Deno {
|
||||||
export function close(rid: number): void;
|
export function close(rid: number): void;
|
||||||
|
|
||||||
/** The Deno abstraction for reading and writing files. */
|
/** The Deno abstraction for reading and writing files. */
|
||||||
|
export class FsFile
|
||||||
|
implements
|
||||||
|
Reader,
|
||||||
|
ReaderSync,
|
||||||
|
Writer,
|
||||||
|
WriterSync,
|
||||||
|
Seeker,
|
||||||
|
SeekerSync,
|
||||||
|
Closer {
|
||||||
|
readonly rid: number;
|
||||||
|
constructor(rid: number);
|
||||||
|
write(p: Uint8Array): Promise<number>;
|
||||||
|
writeSync(p: Uint8Array): number;
|
||||||
|
truncate(len?: number): Promise<void>;
|
||||||
|
truncateSync(len?: number): void;
|
||||||
|
read(p: Uint8Array): Promise<number | null>;
|
||||||
|
readSync(p: Uint8Array): number | null;
|
||||||
|
seek(offset: number, whence: SeekMode): Promise<number>;
|
||||||
|
seekSync(offset: number, whence: SeekMode): number;
|
||||||
|
stat(): Promise<FileInfo>;
|
||||||
|
statSync(): FileInfo;
|
||||||
|
close(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use `Deno.FsFile` instead. `Deno.File` will be removed in Deno 2.0.
|
||||||
|
*
|
||||||
|
* The Deno abstraction for reading and writing files.
|
||||||
|
*/
|
||||||
export class File
|
export class File
|
||||||
implements
|
implements
|
||||||
Reader,
|
Reader,
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
{ path: pathFromURL(path), options, mode },
|
{ path: pathFromURL(path), options, mode },
|
||||||
);
|
);
|
||||||
|
|
||||||
return new File(rid);
|
return new FsFile(rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function open(
|
async function open(
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
{ path: pathFromURL(path), options, mode },
|
{ path: pathFromURL(path), options, mode },
|
||||||
);
|
);
|
||||||
|
|
||||||
return new File(rid);
|
return new FsFile(rid);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createSync(path) {
|
function createSync(path) {
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class File {
|
class FsFile {
|
||||||
#rid = 0;
|
#rid = 0;
|
||||||
|
|
||||||
#readable;
|
#readable;
|
||||||
|
@ -272,7 +272,8 @@
|
||||||
stdin,
|
stdin,
|
||||||
stdout,
|
stdout,
|
||||||
stderr,
|
stderr,
|
||||||
File,
|
File: FsFile,
|
||||||
|
FsFile,
|
||||||
create,
|
create,
|
||||||
createSync,
|
createSync,
|
||||||
open,
|
open,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
((window) => {
|
((window) => {
|
||||||
const core = window.Deno.core;
|
const core = window.Deno.core;
|
||||||
const { File } = window.__bootstrap.files;
|
const { FsFile } = window.__bootstrap.files;
|
||||||
const { readAll } = window.__bootstrap.io;
|
const { readAll } = window.__bootstrap.io;
|
||||||
const { assert, pathFromURL } = window.__bootstrap.util;
|
const { assert, pathFromURL } = window.__bootstrap.util;
|
||||||
const {
|
const {
|
||||||
|
@ -46,15 +46,15 @@
|
||||||
this.pid = res.pid;
|
this.pid = res.pid;
|
||||||
|
|
||||||
if (res.stdinRid && res.stdinRid > 0) {
|
if (res.stdinRid && res.stdinRid > 0) {
|
||||||
this.stdin = new File(res.stdinRid);
|
this.stdin = new FsFile(res.stdinRid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.stdoutRid && res.stdoutRid > 0) {
|
if (res.stdoutRid && res.stdoutRid > 0) {
|
||||||
this.stdout = new File(res.stdoutRid);
|
this.stdout = new FsFile(res.stdoutRid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.stderrRid && res.stderrRid > 0) {
|
if (res.stderrRid && res.stderrRid > 0) {
|
||||||
this.stderr = new File(res.stderrRid);
|
this.stderr = new FsFile(res.stderrRid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@
|
||||||
write: __bootstrap.io.write,
|
write: __bootstrap.io.write,
|
||||||
writeSync: __bootstrap.io.writeSync,
|
writeSync: __bootstrap.io.writeSync,
|
||||||
File: __bootstrap.files.File,
|
File: __bootstrap.files.File,
|
||||||
|
FsFile: __bootstrap.files.FsFile,
|
||||||
open: __bootstrap.files.open,
|
open: __bootstrap.files.open,
|
||||||
openSync: __bootstrap.files.openSync,
|
openSync: __bootstrap.files.openSync,
|
||||||
create: __bootstrap.files.create,
|
create: __bootstrap.files.create,
|
||||||
|
|
Loading…
Add table
Reference in a new issue