mirror of https://github.com/status-im/metro.git
Synchronous file reading
Reviewed By: matryoshcow Differential Revision: D4021460 fbshipit-source-id: 88e4846d4434468d68e6071d05b27e3b7d2ed325
This commit is contained in:
parent
f53d694120
commit
bfc35d528c
|
@ -8,15 +8,11 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const denodeify = require('denodeify');
|
||||
const fs = require('fs');
|
||||
const path = require('./fastpath');
|
||||
|
||||
const {EventEmitter} = require('events');
|
||||
|
||||
const readFile = denodeify(fs.readFile);
|
||||
const stat = denodeify(fs.stat);
|
||||
|
||||
const NOT_FOUND_IN_ROOTS = 'NotFoundInRootsError';
|
||||
|
||||
class Fastfs extends EventEmitter {
|
||||
|
@ -222,14 +218,26 @@ class File {
|
|||
|
||||
read() {
|
||||
if (!this._read) {
|
||||
this._read = readFile(this.path, 'utf8');
|
||||
this._read = new Promise((resolve, reject) => {
|
||||
try {
|
||||
resolve(fs.readFileSync(this.path, 'utf8'));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
return this._read;
|
||||
}
|
||||
|
||||
stat() {
|
||||
if (!this._stat) {
|
||||
this._stat = stat(this.path);
|
||||
this._stat = new Promise((resolve, reject) => {
|
||||
try {
|
||||
resolve(fs.statSync(this.path));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return this._stat;
|
||||
|
|
Loading…
Reference in New Issue