summaryrefslogtreecommitdiff
path: root/std/node/_fs/_fs_dir.ts
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-02-02 19:05:46 +0800
committerGitHub <noreply@github.com>2021-02-02 12:05:46 +0100
commit6abf126c2a7a451cded8c6b5e6ddf1b69c84055d (patch)
treefd94c013a19fcb38954844085821ec1601c20e18 /std/node/_fs/_fs_dir.ts
parenta2b5d44f1aa9d64f448a2a3cc2001272e2f60b98 (diff)
chore: remove std directory (#9361)
This removes the std folder from the tree. Various parts of the tests are pretty tightly dependent on std (47 direct imports and 75 indirect imports, not counting the cli tests that use them as fixtures) so I've added std as a submodule for now.
Diffstat (limited to 'std/node/_fs/_fs_dir.ts')
-rw-r--r--std/node/_fs/_fs_dir.ts91
1 files changed, 0 insertions, 91 deletions
diff --git a/std/node/_fs/_fs_dir.ts b/std/node/_fs/_fs_dir.ts
deleted file mode 100644
index 4f7beec31..000000000
--- a/std/node/_fs/_fs_dir.ts
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
-import Dirent from "./_fs_dirent.ts";
-import { assert } from "../../_util/assert.ts";
-
-export default class Dir {
- private dirPath: string | Uint8Array;
- private syncIterator!: Iterator<Deno.DirEntry> | null;
- private asyncIterator!: AsyncIterator<Deno.DirEntry> | null;
-
- constructor(path: string | Uint8Array) {
- this.dirPath = path;
- }
-
- get path(): string {
- if (this.dirPath instanceof Uint8Array) {
- return new TextDecoder().decode(this.dirPath);
- }
- return this.dirPath;
- }
-
- // deno-lint-ignore no-explicit-any
- read(callback?: (...args: any[]) => void): Promise<Dirent | null> {
- return new Promise((resolve, reject) => {
- if (!this.asyncIterator) {
- this.asyncIterator = Deno.readDir(this.path)[Symbol.asyncIterator]();
- }
- assert(this.asyncIterator);
- this.asyncIterator
- .next()
- .then(({ value }) => {
- resolve(value ? value : null);
- if (callback) {
- callback(null, value ? value : null);
- }
- }, (err) => {
- if (callback) {
- callback(err);
- }
- reject(err);
- });
- });
- }
-
- readSync(): Dirent | null {
- if (!this.syncIterator) {
- this.syncIterator = Deno.readDirSync(this.path)![Symbol.iterator]();
- }
-
- const file: Deno.DirEntry = this.syncIterator.next().value;
-
- return file ? new Dirent(file) : null;
- }
-
- /**
- * Unlike Node, Deno does not require managing resource ids for reading
- * directories, and therefore does not need to close directories when
- * finished reading.
- */
- // deno-lint-ignore no-explicit-any
- close(callback?: (...args: any[]) => void): Promise<void> {
- return new Promise((resolve) => {
- if (callback) {
- callback(null);
- }
- resolve();
- });
- }
-
- /**
- * Unlike Node, Deno does not require managing resource ids for reading
- * directories, and therefore does not need to close directories when
- * finished reading
- */
- closeSync(): void {
- //No op
- }
-
- async *[Symbol.asyncIterator](): AsyncIterableIterator<Dirent> {
- try {
- while (true) {
- const dirent: Dirent | null = await this.read();
- if (dirent === null) {
- break;
- }
- yield dirent;
- }
- } finally {
- await this.close();
- }
- }
-}