BREAKING: Include limited metadata in 'DirEntry' objects (#4941)

This change is to prevent needed a separate stat syscall for each file
when using readdir.

For consistency, this PR also modifies std's `WalkEntry` interface to
extend `DirEntry` with an additional `path` field.
This commit is contained in:
Bert Belder 2020-04-29 22:00:31 +02:00 committed by GitHub
parent 721a4ad59d
commit 3e6ea62841
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 193 additions and 206 deletions

View file

@ -1,21 +1,19 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendSync, sendAsync } from "../dispatch_json.ts";
import { FileInfo, StatResponse, parseFileInfo } from "./stat.ts";
export interface DirEntry extends FileInfo {
export interface DirEntry {
name: string;
isFile: boolean;
isDirectory: boolean;
isSymlink: boolean;
}
interface ReadDirResponse {
entries: StatResponse[];
entries: DirEntry[];
}
function res(response: ReadDirResponse): DirEntry[] {
return response.entries.map(
(statRes: StatResponse): DirEntry => {
return { ...parseFileInfo(statRes), name: statRes.name! };
}
);
return response.entries;
}
export function readdirSync(path: string): Iterable<DirEntry> {

View file

@ -29,8 +29,6 @@ export interface StatResponse {
mtime: number | null;
atime: number | null;
birthtime: number | null;
// Null for stat(), but exists for readdir().
name: string | null;
// Unix only members
dev: number;
ino: number;