use fs.promises.* functions

This commit is contained in:
Conduitry 2020-10-25 20:54:51 -04:00
parent 49f12526c0
commit 13339a82d2
2 changed files with 4 additions and 11 deletions

View File

@ -1,13 +1,10 @@
import { AsyncLocalStorage } from 'async_hooks';
import * as fs from 'fs';
import { resolve } from 'path';
import { promisify } from 'util';
import File from './File';
import Watcher, { WatcherEvent } from './Watcher';
const readFile = promisify(fs.readFile);
export default class Defiler {
// set of original paths for all physical files
paths = new Set<string>();
@ -232,7 +229,7 @@ export default class Defiler {
read = await read({ path, stats: file.stats });
}
if (read) {
file.bytes = await readFile(dir + '/' + path);
file.bytes = await fs.promises.readFile(dir + '/' + path);
}
if (typeof enc === 'function') {
enc = await enc({ path, stats: file.stats, bytes: file.bytes });

View File

@ -1,9 +1,5 @@
import * as EventEmitter from 'events';
import * as fs from 'fs';
import { promisify } from 'util';
const readdir = promisify(fs.readdir);
const stat = promisify(fs.stat);
export default class Watcher extends EventEmitter {
dir: string;
@ -36,7 +32,7 @@ export default class Watcher extends EventEmitter {
// recurse a given directory
private async _recurse(full: string): Promise<void> {
const path = full.slice(this.dir.length + 1);
const stats = await stat(full);
const stats = await fs.promises.stat(full);
if (this.filter && !(await this.filter({ path, stats }))) {
return;
}
@ -46,7 +42,7 @@ export default class Watcher extends EventEmitter {
if (this.watch) {
this._watchers.set(path, fs.watch(full, this._handle.bind(this, full)));
}
await Promise.all((await readdir(full)).map((sub) => this._recurse(full + '/' + sub)));
await Promise.all((await fs.promises.readdir(full)).map((sub) => this._recurse(full + '/' + sub)));
}
}
@ -76,7 +72,7 @@ export default class Watcher extends EventEmitter {
const full = this._queue.shift();
const path = full.slice(this.dir.length + 1);
try {
const stats = await stat(full);
const stats = await fs.promises.stat(full);
if (this.filter && !(await this.filter({ path, stats }))) {
continue;
}