Skip to content

Commit

Permalink
Synchronous file reading
Browse files Browse the repository at this point in the history
Reviewed By: matryoshcow

Differential Revision: D4021460

fbshipit-source-id: 88e4846d4434468d68e6071d05b27e3b7d2ed325
  • Loading branch information
cpojer authored and Facebook Github Bot committed Oct 17, 2016
1 parent d6c5258 commit c84157a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packager/react-packager/src/node-haste/fastfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c84157a

Please sign in to comment.