Skip to content

Commit 83b680d

Browse files
Emily GiurleoJosh Goldberg
authored andcommitted
Replace fs promises api with utils.promisify (#67)
* replace fs promises api with utils.promisify * move line to top of file * promisify writeFile in fsFileSystem
1 parent 8815f7b commit 83b680d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/adapters/fsFileSystem.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import * as fs from "fs";
2+
import { promisify } from "util";
23

34
import { FileSystem } from "./fileSystem";
45

6+
const readFile = promisify(fs.readFile);
7+
const writeFile = promisify(fs.writeFile);
8+
59
export const fsFileSystem: FileSystem = {
610
fileExists: async (filePath: string) => {
711
try {
@@ -12,14 +16,14 @@ export const fsFileSystem: FileSystem = {
1216
},
1317
readFile: async (filePath: string) => {
1418
try {
15-
return (await fs.promises.readFile(filePath)).toString();
19+
return (await readFile(filePath)).toString();
1620
} catch (error) {
1721
return error;
1822
}
1923
},
2024
writeFile: async (filePath: string, contents: string) => {
2125
try {
22-
return fs.promises.writeFile(filePath, contents);
26+
return writeFile(filePath, contents);
2327
} catch (error) {
2428
return error;
2529
}

0 commit comments

Comments
 (0)