Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fs/promises full implementation #1083

Merged
merged 6 commits into from
Aug 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions node/_fs/promises/_fs_readFile.ts

This file was deleted.

18 changes: 0 additions & 18 deletions node/_fs/promises/_fs_writeFile.ts

This file was deleted.

2 changes: 0 additions & 2 deletions node/_fs/promises/mod.ts

This file was deleted.

2 changes: 1 addition & 1 deletion node/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { utimes, utimesSync } from "./_fs/_fs_utimes.ts";
import { watch } from "./_fs/_fs_watch.ts";
import { writeFile, writeFileSync } from "./_fs/_fs_writeFile.ts";

import * as promises from "./_fs/promises/mod.ts";
import * as promises from "./fs/promises.ts";

export default {
access,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { readFile } from "./_fs_readFile.ts";
import * as path from "../../../path/mod.ts";
import { assert, assertEquals } from "../../../testing/asserts.ts";
import { readFile } from "./promises.ts";
import * as path from "../../path/mod.ts";
import { assert, assertEquals } from "../../testing/asserts.ts";

const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
const testData = path.resolve(moduleDir, "..", "testdata", "hello.txt");
const testData = path.resolve(moduleDir, "..", "_fs", "testdata", "hello.txt");

Deno.test("readFileSuccess", async function () {
const data: Uint8Array = await readFile(testData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import {
assertEquals,
assertNotEquals,
assertThrowsAsync,
} from "../../../testing/asserts.ts";
import { writeFile } from "./_fs_writeFile.ts";
import type { TextEncodings } from "../../_utils.ts";
} from "../../testing/asserts.ts";
import { writeFile } from "./promises.ts";
import type { TextEncodings } from "../_utils.ts";

const decoder = new TextDecoder("utf-8");

Deno.test("Invalid encoding results in error()", function testEncodingErrors() {
assertThrowsAsync(
async () => {
// @ts-expect-error Type '"made-up-encoding"' is not assignable to type
await writeFile("some/path", "some data", "made-up-encoding");
},
Error,
Expand All @@ -22,7 +21,6 @@ Deno.test("Invalid encoding results in error()", function testEncodingErrors() {
assertThrowsAsync(
async () => {
await writeFile("some/path", "some data", {
// @ts-expect-error Type '"made-up-encoding"' is not assignable to type
encoding: "made-up-encoding",
});
},
Expand Down
60 changes: 60 additions & 0 deletions node/fs/promises.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { promisify } from "../util.ts";
import * as fs from "../fs.ts";

export const access = promisify(fs.access);
export const copyFile = promisify(fs.copyFile);
export const open = promisify(fs.open);
// export const opendir = promisify(fs.opendir);
export const rename = promisify(fs.rename);
export const truncate = promisify(fs.truncate);
// export const rm = promisify(fs.rm);
export const rmdir = promisify(fs.rmdir);
export const mkdir = promisify(fs.mkdir);
export const readdir = promisify(fs.readdir);
export const readlink = promisify(fs.readlink);
export const symlink = promisify(fs.symlink);
export const lstat = promisify(fs.lstat);
export const stat = promisify(fs.stat);
export const link = promisify(fs.link);
export const unlink = promisify(fs.unlink);
export const chmod = promisify(fs.chmod);
// export const lchmod = promisify(fs.lchmod);
// export const lchown = promisify(fs.lchown);
export const chown = promisify(fs.chown);
export const utimes = promisify(fs.utimes);
// export const lutimes = promisify(fs.lutimes);
export const realpath = promisify(fs.realpath);
export const mkdtemp = promisify(fs.mkdtemp);
export const writeFile = promisify(fs.writeFile);
export const appendFile = promisify(fs.appendFile);
export const readFile = promisify(fs.readFile);
export const watch = promisify(fs.watch);

export default {
open,
// opendir,
rename,
truncate,
// rm,
rmdir,
mkdir,
readdir,
readlink,
symlink,
lstat,
stat,
link,
unlink,
chmod,
// lchmod,
// lchown,
chown,
utimes,
// lutimes,
realpath,
mkdtemp,
writeFile,
appendFile,
readFile,
watch,
};