MCPcopy Create free account
hub / github.com/denoland/std / NodeFsFile

Class NodeFsFile

fs/_node_fs_file.ts:11–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9 * The internal class to convert a Node file descriptor into a FsFile object.
10 */
11export class NodeFsFile implements FsFile {
12 #nodeFs = getNodeFs();
13 #nodeStream = getNodeStream();
14 #nodeTty = getNodeTty();
15 #nodeUtil = getNodeUtil();
16 #nodeReadFd = this.#nodeUtil.promisify(this.#nodeFs.read);
17 #nodeWriteFd = this.#nodeUtil.promisify(this.#nodeFs.write);
18
19 #closed: boolean;
20 #rid: number;
21 #readableStream?: ReadableStream<Uint8Array>;
22 #writableStream?: WritableStream<Uint8Array>;
23
24 constructor(fd: number) {
25 this.#rid = fd;
26 this.#closed = false;
27 }
28
29 get readable(): ReadableStream<Uint8Array> {
30 if (this.#readableStream == null) {
31 const readStream = this.#nodeFs.createReadStream(null as unknown, {
32 fd: this.#rid,
33 autoClose: false,
34 });
35 this.#readableStream = this.#nodeStream.Readable.toWeb(readStream);
36 }
37 return this.#readableStream as ReadableStream;
38 }
39
40 get writable(): WritableStream<Uint8Array> {
41 if (this.#writableStream == null) {
42 const writeStream = this.#nodeFs.createWriteStream(null as unknown, {
43 fd: this.#rid,
44 autoClose: false,
45 });
46 this.#writableStream = this.#nodeStream.Writable.toWeb(writeStream);
47 }
48 return this.#writableStream as WritableStream;
49 }
50
51 [Symbol.dispose](): void {
52 if (!this.#closed) {
53 this.close();
54 }
55 }
56
57 close(): void {
58 this.#closed = true;
59 this.#nodeFs.closeSync(this.#rid);
60 }
61
62 isTerminal(): boolean {
63 return this.#nodeTty.isatty(this.#rid);
64 }
65
66 // deno-lint-ignore require-await no-unused-vars
67 async lock(exclusive?: boolean): Promise<void> {
68 throw new Error("Method not implemented");

Callers

nothing calls this directly

Calls 4

getNodeFsFunction · 0.90
getNodeStreamFunction · 0.90
getNodeTtyFunction · 0.90
getNodeUtilFunction · 0.90

Tested by

no test coverage detected