| 9 | * The internal class to convert a Node file descriptor into a FsFile object. |
| 10 | */ |
| 11 | export 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"); |
nothing calls this directly
no test coverage detected