summaryrefslogtreecommitdiff
path: root/cli/js/ops/fs/read_dir.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/ops/fs/read_dir.ts')
-rw-r--r--cli/js/ops/fs/read_dir.ts26
1 files changed, 17 insertions, 9 deletions
diff --git a/cli/js/ops/fs/read_dir.ts b/cli/js/ops/fs/read_dir.ts
index c48104d4b..29b8676ef 100644
--- a/cli/js/ops/fs/read_dir.ts
+++ b/cli/js/ops/fs/read_dir.ts
@@ -1,24 +1,32 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
-import { FileInfo, FileInfoImpl } from "../../file_info.ts";
-import { StatResponse } from "./stat.ts";
+import { FileInfo, StatResponse, parseFileInfo } from "./stat.ts";
+
+export interface DirEntry extends FileInfo {
+ name: string;
+}
interface ReadDirResponse {
entries: StatResponse[];
}
-function res(response: ReadDirResponse): FileInfo[] {
+function res(response: ReadDirResponse): DirEntry[] {
return response.entries.map(
- (statRes: StatResponse): FileInfo => {
- return new FileInfoImpl(statRes);
+ (statRes: StatResponse): DirEntry => {
+ return { ...parseFileInfo(statRes), name: statRes.name! };
}
);
}
-export function readdirSync(path: string): FileInfo[] {
- return res(sendSync("op_read_dir", { path }));
+export function readdirSync(path: string): Iterable<DirEntry> {
+ return res(sendSync("op_read_dir", { path }))[Symbol.iterator]();
}
-export async function readdir(path: string): Promise<FileInfo[]> {
- return res(await sendAsync("op_read_dir", { path }));
+export function readdir(path: string): AsyncIterable<DirEntry> {
+ const array = sendAsync("op_read_dir", { path }).then(res);
+ return {
+ async *[Symbol.asyncIterator](): AsyncIterableIterator<DirEntry> {
+ yield* await array;
+ },
+ };
}