Skip to content

Commit

Permalink
Necessary evil
Browse files Browse the repository at this point in the history
  • Loading branch information
tschaub committed Jul 8, 2016
1 parent 0fb4621 commit f0a3783
Showing 1 changed file with 5 additions and 41 deletions.
46 changes: 5 additions & 41 deletions node/fs-6.3.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
const util = require('util');
const pathModule = require('path');

const binding = process.binding('fs');
let binding = process.binding('fs');
const constants = require('constants');
const fs = exports;
const Buffer = require('buffer').Buffer;
Expand Down Expand Up @@ -35,42 +35,6 @@ const isWindows = process.platform === 'win32';
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
const errnoException = util._errnoException;

var printDeprecation;
try {
printDeprecation = require('internal/util').printDeprecationMessage;
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') throw e;

// TODO(ChALkeR): remove this in master after 6.x
// This code was based upon internal/util and is required to give users
// a grace period before actually breaking modules that re-evaluate fs
// sources from context where internal modules are not allowed, e.g.
// older versions of graceful-fs module.

const prefix = `(${process.release.name}:${process.pid}) `;

printDeprecation = function(msg, warned) {
if (process.noDeprecation)
return true;

if (warned)
return warned;

if (process.throwDeprecation)
throw new Error(`${prefix}${msg}`);
else if (process.traceDeprecation)
console.trace(msg);
else
console.error(`${prefix}${msg}`);

return true;
};
printDeprecation('fs: re-evaluating native module sources is not ' +
'supported. If you are using the graceful-fs module, ' +
'please update it to a more recent version.',
false);
}

function throwOptionsError(options) {
throw new TypeError('Expected options to be either an object or a string, ' +
'but got ' + typeof options + ' instead');
Expand Down Expand Up @@ -285,7 +249,7 @@ fs.readFile = function(path, options, callback_) {
context.isUserFd = isFd(path); // file descriptor ownership
var req = new FSReqWrap();
req.context = context;
req.oncomplete = readFileAfterOpen;
req.oncomplete = readFileAfterOpen.bind(req);

if (context.isUserFd) {
process.nextTick(function() {
Expand Down Expand Up @@ -330,15 +294,15 @@ ReadFileContext.prototype.read = function() {
}

var req = new FSReqWrap();
req.oncomplete = readFileAfterRead;
req.oncomplete = readFileAfterRead.bind(req);
req.context = this;

binding.read(this.fd, buffer, offset, length, -1, req);
};

ReadFileContext.prototype.close = function(err) {
var req = new FSReqWrap();
req.oncomplete = readFileAfterClose;
req.oncomplete = readFileAfterClose.bind(req);
req.context = this;
this.err = err;

Expand All @@ -363,7 +327,7 @@ function readFileAfterOpen(err, fd) {
context.fd = fd;

var req = new FSReqWrap();
req.oncomplete = readFileAfterStat;
req.oncomplete = readFileAfterStat.bind(req);
req.context = context;
binding.fstat(fd, req);
}
Expand Down

0 comments on commit f0a3783

Please sign in to comment.