@@ -14,6 +14,9 @@ const Stream = require('stream').Stream;
14
14
const EventEmitter = require ( 'events' ) ;
15
15
const FSReqWrap = binding . FSReqWrap ;
16
16
const FSEvent = process . binding ( 'fs_event_wrap' ) . FSEvent ;
17
+ const internalFS = require ( 'internal/fs' ) ;
18
+ const assertEncoding = internalFS . assertEncoding ;
19
+ const SyncWriteStream = internalFS . SyncWriteStream ;
17
20
18
21
Object . defineProperty ( exports , 'constants' , {
19
22
configurable : false ,
@@ -96,12 +99,6 @@ function makeCallback(cb) {
96
99
} ;
97
100
}
98
101
99
- function assertEncoding ( encoding ) {
100
- if ( encoding && ! Buffer . isEncoding ( encoding ) ) {
101
- throw new Error ( 'Unknown encoding: ' + encoding ) ;
102
- }
103
- }
104
-
105
102
function nullCheck ( path , callback ) {
106
103
if ( ( '' + path ) . indexOf ( '\u0000' ) !== - 1 ) {
107
104
var er = new Error ( 'Path must be a string without null bytes' ) ;
@@ -2144,75 +2141,12 @@ WriteStream.prototype.close = ReadStream.prototype.close;
2144
2141
// There is no shutdown() for files.
2145
2142
WriteStream . prototype . destroySoon = WriteStream . prototype . end ;
2146
2143
2147
-
2148
2144
// 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.
2165
2148
Object . defineProperty ( fs , 'SyncWriteStream' , {
2166
2149
configurable : true ,
2167
2150
writable : true ,
2168
2151
value : SyncWriteStream
2169
2152
} ) ;
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