@@ -14,6 +14,9 @@ const Stream = require('stream').Stream;
1414const EventEmitter = require ( 'events' ) ;
1515const FSReqWrap = binding . FSReqWrap ;
1616const FSEvent = process . binding ( 'fs_event_wrap' ) . FSEvent ;
17+ const internalFS = require ( 'internal/fs' ) ;
18+ const assertEncoding = internalFS . assertEncoding ;
19+ const SyncWriteStream = internalFS . SyncWriteStream ;
1720
1821Object . defineProperty ( exports , 'constants' , {
1922 configurable : false ,
@@ -96,12 +99,6 @@ function makeCallback(cb) {
9699 } ;
97100}
98101
99- function assertEncoding ( encoding ) {
100- if ( encoding && ! Buffer . isEncoding ( encoding ) ) {
101- throw new Error ( 'Unknown encoding: ' + encoding ) ;
102- }
103- }
104-
105102function nullCheck ( path , callback ) {
106103 if ( ( '' + path ) . indexOf ( '\u0000' ) !== - 1 ) {
107104 var er = new Error ( 'Path must be a string without null bytes' ) ;
@@ -2144,75 +2141,12 @@ WriteStream.prototype.close = ReadStream.prototype.close;
21442141// There is no shutdown() for files.
21452142WriteStream . prototype . destroySoon = WriteStream . prototype . end ;
21462143
2147-
21482144// SyncWriteStream is internal. DO NOT USE.
2149- // Temporary hack for process.stdout and process.stderr when piped to files.
2150- function SyncWriteStream ( fd , options ) {
2151- Stream . call ( this ) ;
2152-
2153- options = options || { } ;
2154-
2155- this . fd = fd ;
2156- this . writable = true ;
2157- this . readable = false ;
2158- this . autoClose = options . autoClose === undefined ? true : options . autoClose ;
2159- }
2160-
2161- util . inherits ( SyncWriteStream , Stream ) ;
2162-
2163-
2164- // Export
2145+ // todo(jasnell): "Docs-only" deprecation for now. This was never documented
2146+ // so there's no documentation to modify. In the future, add a runtime
2147+ // deprecation.
21652148Object . defineProperty ( fs , 'SyncWriteStream' , {
21662149 configurable : true ,
21672150 writable : true ,
21682151 value : SyncWriteStream
21692152} ) ;
2170-
2171- SyncWriteStream . prototype . write = function ( data , arg1 , arg2 ) {
2172- var encoding , cb ;
2173-
2174- // parse arguments
2175- if ( arg1 ) {
2176- if ( typeof arg1 === 'string' ) {
2177- encoding = arg1 ;
2178- cb = arg2 ;
2179- } else if ( typeof arg1 === 'function' ) {
2180- cb = arg1 ;
2181- } else {
2182- throw new Error ( 'Bad arguments' ) ;
2183- }
2184- }
2185- assertEncoding ( encoding ) ;
2186-
2187- // Change strings to buffers. SLOW
2188- if ( typeof data === 'string' ) {
2189- data = Buffer . from ( data , encoding ) ;
2190- }
2191-
2192- fs . writeSync ( this . fd , data , 0 , data . length ) ;
2193-
2194- if ( cb ) {
2195- process . nextTick ( cb ) ;
2196- }
2197-
2198- return true ;
2199- } ;
2200-
2201-
2202- SyncWriteStream . prototype . end = function ( data , arg1 , arg2 ) {
2203- if ( data ) {
2204- this . write ( data , arg1 , arg2 ) ;
2205- }
2206- this . destroy ( ) ;
2207- } ;
2208-
2209-
2210- SyncWriteStream . prototype . destroy = function ( ) {
2211- if ( this . autoClose )
2212- fs . closeSync ( this . fd ) ;
2213- this . fd = null ;
2214- this . emit ( 'close' ) ;
2215- return true ;
2216- } ;
2217-
2218- SyncWriteStream . prototype . destroySoon = SyncWriteStream . prototype . destroy ;
0 commit comments