@@ -36,6 +36,8 @@ const isWindows = process.platform === 'win32';
3636const DEBUG = process . env . NODE_DEBUG && / f s / . test ( process . env . NODE_DEBUG ) ;
3737const errnoException = util . _errnoException ;
3838
39+ const internalUtil = require ( 'internal/util' ) ;
40+
3941function throwOptionsError ( options ) {
4042 throw new TypeError ( 'Expected options to be either an object or a string, ' +
4143 'but got ' + typeof options + ' instead' ) ;
@@ -1608,6 +1610,8 @@ fs.createReadStream = function(path, options) {
16081610 return new ReadStream ( path , options ) ;
16091611} ;
16101612
1613+ var warnedReadStreamOptions = false ;
1614+
16111615util . inherits ( ReadStream , Readable ) ;
16121616fs . ReadStream = ReadStream ;
16131617
@@ -1619,8 +1623,14 @@ function ReadStream(path, options) {
16191623 options = { } ;
16201624 else if ( typeof options === 'string' )
16211625 options = { encoding : options } ;
1622- else if ( options === null || typeof options !== 'object' )
1623- throw new TypeError ( 'options must be a string or an object' ) ;
1626+ else if ( options === null || typeof options !== 'object' ) {
1627+ warnedReadStreamOptions = internalUtil . printDeprecationMessage (
1628+ 'Passing anything but an object or a string as the second argument to ' +
1629+ 'ReadStream is deprecated.' ,
1630+ warnedReadStreamOptions
1631+ ) ;
1632+ options = options || { } ;
1633+ }
16241634
16251635 // a little bit bigger buffer and water marks by default
16261636 options = Object . create ( options ) ;
@@ -1780,6 +1790,8 @@ fs.createWriteStream = function(path, options) {
17801790 return new WriteStream ( path , options ) ;
17811791} ;
17821792
1793+ var warnedWriteStreamOptions = false ;
1794+
17831795util . inherits ( WriteStream , Writable ) ;
17841796fs . WriteStream = WriteStream ;
17851797function WriteStream ( path , options ) {
@@ -1790,10 +1802,16 @@ function WriteStream(path, options) {
17901802 options = { } ;
17911803 else if ( typeof options === 'string' )
17921804 options = { encoding : options } ;
1793- else if ( options === null || typeof options !== 'object' )
1794- throw new TypeError ( 'options must be a string or an object' ) ;
1795-
1796- options = Object . create ( options ) ;
1805+ else if ( options === null || typeof options !== 'object' ) {
1806+ warnedWriteStreamOptions = internalUtil . printDeprecationMessage (
1807+ 'Passing anything but an object or a string as the second argument to ' +
1808+ 'WriteStream is deprecated.' ,
1809+ warnedWriteStreamOptions
1810+ ) ;
1811+ options = options || { } ;
1812+ } else {
1813+ options = Object . create ( options ) ;
1814+ }
17971815
17981816 Writable . call ( this , options ) ;
17991817
0 commit comments