mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
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:
parent
721a4ad59d
commit
3e6ea62841
14 changed files with 193 additions and 206 deletions
|
@ -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> {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue