Skip to content

Commit

Permalink
fs: Replace an Error with a deprecation message.
Browse files Browse the repository at this point in the history
This fixes a breaking change in commit
353e26e.
  • Loading branch information
ChALkeR committed Jun 17, 2015
1 parent 96165f9 commit 8fd60f4
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const isWindows = process.platform === 'win32';
const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
const errnoException = util._errnoException;

const internalUtil = require('internal/util');

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 @@ -1608,6 +1610,8 @@ fs.createReadStream = function(path, options) {
return new ReadStream(path, options);
};

var warnedReadStreamOptions = false;

util.inherits(ReadStream, Readable);
fs.ReadStream = ReadStream;

Expand All @@ -1619,8 +1623,14 @@ function ReadStream(path, options) {
options = {};
else if (typeof options === 'string')
options = { encoding: options };
else if (options === null || typeof options !== 'object')
throw new TypeError('options must be a string or an object');
else if (options === null || typeof options !== 'object') {
warnedReadStreamOptions = internalUtil.printDeprecationMessage(
'Passing anything but an object or a string as the second argument to ' +
'ReadStream is deprecated.',
warnedReadStreamOptions
);
options = options || {};
}

// a little bit bigger buffer and water marks by default
options = Object.create(options);
Expand Down Expand Up @@ -1780,6 +1790,8 @@ fs.createWriteStream = function(path, options) {
return new WriteStream(path, options);
};

var warnedWriteStreamOptions = false;

util.inherits(WriteStream, Writable);
fs.WriteStream = WriteStream;
function WriteStream(path, options) {
Expand All @@ -1790,10 +1802,16 @@ function WriteStream(path, options) {
options = {};
else if (typeof options === 'string')
options = { encoding: options };
else if (options === null || typeof options !== 'object')
throw new TypeError('options must be a string or an object');

options = Object.create(options);
else if (options === null || typeof options !== 'object') {
warnedWriteStreamOptions = internalUtil.printDeprecationMessage(
'Passing anything but an object or a string as the second argument to ' +
'WriteStream is deprecated.',
warnedWriteStreamOptions
);
options = options || {};
} else {
options = Object.create(options);
}

Writable.call(this, options);

Expand Down

0 comments on commit 8fd60f4

Please sign in to comment.