未验证 提交 9a63902d 编写于 作者: D dubiousjim 提交者: GitHub

Rename readDir -> readdir (#4225)

上级 afea9b2e
......@@ -111,7 +111,7 @@ export {
ProcessStatus,
Signal
} from "./process.ts";
export { readDirSync, readDir } from "./read_dir.ts";
export { readdirSync, readdir } from "./read_dir.ts";
export { readFileSync, readFile } from "./read_file.ts";
export { readlinkSync, readlink } from "./read_link.ts";
export { realpathSync, realpath } from "./realpath.ts";
......
......@@ -3,8 +3,8 @@ import { StatResponse } from "./stat.ts";
import { build } from "./build.ts";
/** A FileInfo describes a file and is returned by `stat`, `lstat`,
* `statSync`, `lstatSync`. A list of FileInfo is returned by `readDir`,
* `readDirSync`. */
* `statSync`, `lstatSync`. A list of FileInfo is returned by `readdir`,
* `readdirSync`. */
export interface FileInfo {
/** The size of the file, in bytes. */
len: number;
......
......@@ -992,8 +992,8 @@ declare namespace Deno {
/** UNSTABLE: 'len' maybe should be 'length' or 'size'.
*
* A FileInfo describes a file and is returned by `stat`, `lstat`,
* `statSync`, `lstatSync`. A list of FileInfo is returned by `readDir`,
* `readDirSync`. */
* `statSync`, `lstatSync`. A list of FileInfo is returned by `readdir`,
* `readdirSync`. */
export interface FileInfo {
/** **UNSTABLE**: `.len` maybe should be `.length` or `.size`.
*
......@@ -1079,25 +1079,24 @@ declare namespace Deno {
// @url js/read_dir.d.ts
/** UNSTABLE: Unstable rename to readdirSync.
/** UNSTABLE: need to consider streaming case
*
/* Synchronously reads the directory given by `path` and returns an array of
* Synchronously reads the directory given by `path` and returns an array of
* `Deno.FileInfo`.
*
* const files = Deno.readDirSync("/");
* const files = Deno.readdirSync("/");
*
* Requires `allow-read` permission. */
export function readDirSync(path: string): FileInfo[];
export function readdirSync(path: string): FileInfo[];
/** UNSTABLE: Possibly rename to `.readdir()`. Maybe need to return an
* `AsyncIterable`.
/** UNSTABLE: Maybe need to return an `AsyncIterable`.
*
* Reads the directory given by `path` and resolves to an array of `Deno.FileInfo`.
*
* const files = await Deno.readDir("/");
* const files = await Deno.readdir("/");
*
* Requires `allow-read` permission. */
export function readDir(path: string): Promise<FileInfo[]>;
export function readdir(path: string): Promise<FileInfo[]>;
// @url js/copy_file.d.ts
......
......@@ -18,10 +18,10 @@ function res(response: ReadDirResponse): FileInfo[] {
/** Synchronously reads the directory given by `path` and returns an array of
* `Deno.FileInfo`.
*
* const files = Deno.readDirSync("/");
* const files = Deno.readdirSync("/");
*
* Requires `allow-read` permission. */
export function readDirSync(path: string): FileInfo[] {
export function readdirSync(path: string): FileInfo[] {
return res(sendSync("op_read_dir", { path }));
}
......@@ -29,9 +29,9 @@ export function readDirSync(path: string): FileInfo[] {
*
* Reads the directory given by `path` and resolves to an array of `Deno.FileInfo`.
*
* const files = await Deno.readDir("/");
* const files = await Deno.readdir("/");
*
* Requires `allow-read` permission. */
export async function readDir(path: string): Promise<FileInfo[]> {
export async function readdir(path: string): Promise<FileInfo[]> {
return res(await sendAsync("op_read_dir", { path }));
}
......@@ -21,15 +21,15 @@ function assertSameContent(files: FileInfo[]): void {
assertEquals(counter, 2);
}
unitTest({ perms: { read: true } }, function readDirSyncSuccess(): void {
const files = Deno.readDirSync("cli/tests/");
unitTest({ perms: { read: true } }, function readdirSyncSuccess(): void {
const files = Deno.readdirSync("cli/tests/");
assertSameContent(files);
});
unitTest({ perms: { read: false } }, function readDirSyncPerm(): void {
unitTest({ perms: { read: false } }, function readdirSyncPerm(): void {
let caughtError = false;
try {
Deno.readDirSync("tests/");
Deno.readdirSync("tests/");
} catch (e) {
caughtError = true;
assert(e instanceof Deno.errors.PermissionDenied);
......@@ -37,12 +37,12 @@ unitTest({ perms: { read: false } }, function readDirSyncPerm(): void {
assert(caughtError);
});
unitTest({ perms: { read: true } }, function readDirSyncNotDir(): void {
unitTest({ perms: { read: true } }, function readdirSyncNotDir(): void {
let caughtError = false;
let src;
try {
src = Deno.readDirSync("cli/tests/fixture.json");
src = Deno.readdirSync("cli/tests/fixture.json");
} catch (err) {
caughtError = true;
assert(err instanceof Error);
......@@ -51,12 +51,12 @@ unitTest({ perms: { read: true } }, function readDirSyncNotDir(): void {
assertEquals(src, undefined);
});
unitTest({ perms: { read: true } }, function readDirSyncNotFound(): void {
unitTest({ perms: { read: true } }, function readdirSyncNotFound(): void {
let caughtError = false;
let src;
try {
src = Deno.readDirSync("bad_dir_name");
src = Deno.readdirSync("bad_dir_name");
} catch (err) {
caughtError = true;
assert(err instanceof Deno.errors.NotFound);
......@@ -65,19 +65,19 @@ unitTest({ perms: { read: true } }, function readDirSyncNotFound(): void {
assertEquals(src, undefined);
});
unitTest({ perms: { read: true } }, async function readDirSuccess(): Promise<
unitTest({ perms: { read: true } }, async function readdirSuccess(): Promise<
void
> {
const files = await Deno.readDir("cli/tests/");
const files = await Deno.readdir("cli/tests/");
assertSameContent(files);
});
unitTest({ perms: { read: false } }, async function readDirPerm(): Promise<
unitTest({ perms: { read: false } }, async function readdirPerm(): Promise<
void
> {
let caughtError = false;
try {
await Deno.readDir("tests/");
await Deno.readdir("tests/");
} catch (e) {
caughtError = true;
assert(e instanceof Deno.errors.PermissionDenied);
......
......@@ -385,7 +385,7 @@ unitTest(
unitTest(
{ perms: { read: true } },
async function assertAllUnitTestFilesImported(): Promise<void> {
const directoryTestFiles = Deno.readDirSync("./cli/js")
const directoryTestFiles = Deno.readdirSync("./cli/js")
.map(k => k.name)
.filter(file => file!.endsWith("_test.ts"));
const unitTestsFile: Uint8Array = Deno.readFileSync(
......
......@@ -157,7 +157,7 @@ async function copyDir(
await Deno.utime(dest, srcStatInfo.accessed, srcStatInfo.modified);
}
const files = await Deno.readDir(src);
const files = await Deno.readdir(src);
for (const file of files) {
assert(file.name != null, "file.name must be set");
......@@ -188,7 +188,7 @@ function copyDirSync(src: string, dest: string, options: CopyOptions): void {
Deno.utimeSync(dest, srcStatInfo.accessed, srcStatInfo.modified);
}
const files = Deno.readDirSync(src);
const files = Deno.readdirSync(src);
for (const file of files) {
assert(file.name != null, "file.name must be set");
......
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { join } from "../path/mod.ts";
const { readDir, readDirSync, mkdir, mkdirSync, remove, removeSync } = Deno;
const { readdir, readdirSync, mkdir, mkdirSync, remove, removeSync } = Deno;
/**
* Ensures that a directory is empty.
* Deletes directory contents if the directory is not empty.
......@@ -10,7 +10,7 @@ const { readDir, readDirSync, mkdir, mkdirSync, remove, removeSync } = Deno;
*/
export async function emptyDir(dir: string): Promise<void> {
try {
const items = await readDir(dir);
const items = await readdir(dir);
while (items.length) {
const item = items.shift();
......@@ -38,7 +38,7 @@ export async function emptyDir(dir: string): Promise<void> {
*/
export function emptyDirSync(dir: string): void {
try {
const items = readDirSync(dir);
const items = readdirSync(dir);
// if directory already exist. then remove it's child item.
while (items.length) {
......
......@@ -3,7 +3,7 @@
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
import { unimplemented, assert } from "../testing/asserts.ts";
import { join } from "../path/mod.ts";
const { readDir, readDirSync, stat, statSync } = Deno;
const { readdir, readdirSync, stat, statSync } = Deno;
type FileInfo = Deno.FileInfo;
export interface WalkOptions {
......@@ -79,7 +79,7 @@ export async function* walk(
if (maxDepth < 1 || !include(root, undefined, undefined, skip)) {
return;
}
const ls: FileInfo[] = await readDir(root);
const ls: FileInfo[] = await readdir(root);
for (const info of ls) {
if (info.isSymlink()) {
if (followSymlinks) {
......@@ -133,7 +133,7 @@ export function* walkSync(
if (maxDepth < 1 || !include(root, undefined, undefined, skip)) {
return;
}
const ls: FileInfo[] = readDirSync(root);
const ls: FileInfo[] = readdirSync(root);
for (const info of ls) {
if (info.isSymlink()) {
if (followSymlinks) {
......
......@@ -6,7 +6,7 @@
// TODO Add tests like these:
// https://github.com/indexzero/http-server/blob/master/test/http-server-test.js
const { args, stat, readDir, open, exit } = Deno;
const { args, stat, readdir, open, exit } = Deno;
import { posix } from "../path/mod.ts";
import { listenAndServe, ServerRequest, Response } from "./server.ts";
import { parse } from "../flags/mod.ts";
......@@ -113,14 +113,14 @@ async function serveFile(
return res;
}
// TODO: simplify this after deno.stat and deno.readDir are fixed
// TODO: simplify this after deno.stat and deno.readdir are fixed
async function serveDir(
req: ServerRequest,
dirPath: string
): Promise<Response> {
const dirUrl = `/${posix.relative(target, dirPath)}`;
const listEntry: EntryInfo[] = [];
const fileInfos = await readDir(dirPath);
const fileInfos = await readdir(dirPath);
for (const fileInfo of fileInfos) {
const filePath = posix.join(dirPath, fileInfo.name ?? "");
const fileUrl = posix.join(dirUrl, fileInfo.name ?? "");
......
......@@ -29,7 +29,7 @@ export default class Dir {
return new Promise(async (resolve, reject) => {
try {
if (this.initializationOfDirectoryFilesIsRequired()) {
const denoFiles: Deno.FileInfo[] = await Deno.readDir(this.path);
const denoFiles: Deno.FileInfo[] = await Deno.readdir(this.path);
this.files = denoFiles.map(file => new Dirent(file));
}
const nextFile = this.files.pop();
......@@ -55,7 +55,7 @@ export default class Dir {
readSync(): Dirent | null {
if (this.initializationOfDirectoryFilesIsRequired()) {
this.files.push(
...Deno.readDirSync(this.path).map(file => new Dirent(file))
...Deno.readdirSync(this.path).map(file => new Dirent(file))
);
}
const dirent: Dirent | undefined = this.files.pop();
......
......@@ -133,9 +133,9 @@ test readFileSyncNotFound_permW0N0E0
... ok
test readFileSuccess_permW0N0E0
... ok
test readDirSyncNotDir_permW0N0E0
test readdirSyncNotDir_permW0N0E0
... ok
test readDirSyncNotFound_permW0N0E0
test readdirSyncNotFound_permW0N0E0
... ok
test writeFileSyncPerm_permW0N0E0
... ok
......
......@@ -163,9 +163,9 @@ test readFileSyncNotFound_permW0N0E0
... ok
test readFileSuccess_permW0N0E0
... ok
test readDirSyncNotDir_permW0N0E0
test readdirSyncNotDir_permW0N0E0
... ok
test readDirSyncNotFound_permW0N0E0
test readdirSyncNotFound_permW0N0E0
... ok
test writeFileSyncPerm_permW0N0E0
... ok
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册