@@ -8,116 +8,115 @@ CONSTANTS.NODE_CLIENT = true;
8
8
*/
9
9
( function ( ) {
10
10
var version = process [ 'version' ] ;
11
- if ( version === 'v0.10.22' || version === 'v0.10.23' || version === 'v0.10.24' ) {
12
- /**
13
- * The following duplicates much of `/lib/_stream_writable.js` at
14
- * b922b5e90d2c14dd332b95827c2533e083df7e55, applying the fix for
15
- * https://github.com/joyent/node/issues/6506. Note that this fix also
16
- * needs to be applied to `Duplex.prototype.write()` (in
17
- * `/lib/_stream_duplex.js`) as well.
18
- */
19
- var Writable = require ( '_stream_writable' ) ;
20
-
21
- Writable [ 'prototype' ] [ 'write' ] = function ( chunk , encoding , cb ) {
22
- var state = this [ '_writableState' ] ;
23
- var ret = false ;
24
-
25
- if ( typeof encoding === 'function' ) {
26
- cb = encoding ;
27
- encoding = null ;
28
- }
29
-
30
- if ( Buffer [ 'isBuffer' ] ( chunk ) )
31
- encoding = 'buffer' ;
32
- else if ( ! encoding )
33
- encoding = state [ 'defaultEncoding' ] ;
34
-
35
- if ( typeof cb !== 'function' )
36
- cb = function ( ) { } ;
37
-
38
- if ( state [ 'ended' ] )
39
- writeAfterEnd ( this , state , cb ) ;
40
- else if ( validChunk ( this , state , chunk , cb ) )
41
- ret = writeOrBuffer ( this , state , chunk , encoding , cb ) ;
42
-
43
- return ret ;
44
- } ;
45
-
46
- function writeAfterEnd ( stream , state , cb ) {
47
- var er = new Error ( 'write after end' ) ;
48
- // TODO: defer error events consistently everywhere, not just the cb
11
+ if ( version !== 'v0.10.22' && version !== 'v0.10.23' && version !== 'v0.10.24' ) return ;
12
+ /**
13
+ * The following duplicates much of `/lib/_stream_writable.js` at
14
+ * b922b5e90d2c14dd332b95827c2533e083df7e55, applying the fix for
15
+ * https://github.com/joyent/node/issues/6506. Note that this fix also
16
+ * needs to be applied to `Duplex.prototype.write()` (in
17
+ * `/lib/_stream_duplex.js`) as well.
18
+ */
19
+ var Writable = require ( '_stream_writable' ) ;
20
+
21
+ Writable [ 'prototype' ] [ 'write' ] = function ( chunk , encoding , cb ) {
22
+ var state = this [ '_writableState' ] ;
23
+ var ret = false ;
24
+
25
+ if ( typeof encoding === 'function' ) {
26
+ cb = encoding ;
27
+ encoding = null ;
28
+ }
29
+
30
+ if ( Buffer [ 'isBuffer' ] ( chunk ) )
31
+ encoding = 'buffer' ;
32
+ else if ( ! encoding )
33
+ encoding = state [ 'defaultEncoding' ] ;
34
+
35
+ if ( typeof cb !== 'function' )
36
+ cb = function ( ) { } ;
37
+
38
+ if ( state [ 'ended' ] )
39
+ writeAfterEnd ( this , state , cb ) ;
40
+ else if ( validChunk ( this , state , chunk , cb ) )
41
+ ret = writeOrBuffer ( this , state , chunk , encoding , cb ) ;
42
+
43
+ return ret ;
44
+ } ;
45
+
46
+ function writeAfterEnd ( stream , state , cb ) {
47
+ var er = new Error ( 'write after end' ) ;
48
+ // TODO: defer error events consistently everywhere, not just the cb
49
+ stream [ 'emit' ] ( 'error' , er ) ;
50
+ process [ 'nextTick' ] ( function ( ) {
51
+ cb ( er ) ;
52
+ } ) ;
53
+ }
54
+
55
+ function validChunk ( stream , state , chunk , cb ) {
56
+ var valid = true ;
57
+ if ( ! Buffer [ 'isBuffer' ] ( chunk ) &&
58
+ 'string' !== typeof chunk &&
59
+ chunk !== null &&
60
+ chunk !== undefined &&
61
+ ! state [ 'objectMode' ] ) {
62
+ var er = new TypeError ( 'Invalid non-string/buffer chunk' ) ;
49
63
stream [ 'emit' ] ( 'error' , er ) ;
50
64
process [ 'nextTick' ] ( function ( ) {
51
65
cb ( er ) ;
52
66
} ) ;
67
+ valid = false ;
53
68
}
69
+ return valid ;
70
+ }
54
71
55
- function validChunk ( stream , state , chunk , cb ) {
56
- var valid = true ;
57
- if ( ! Buffer [ 'isBuffer' ] ( chunk ) &&
58
- 'string' !== typeof chunk &&
59
- chunk !== null &&
60
- chunk !== undefined &&
61
- ! state [ 'objectMode' ] ) {
62
- var er = new TypeError ( 'Invalid non-string/buffer chunk' ) ;
63
- stream [ 'emit' ] ( 'error' , er ) ;
64
- process [ 'nextTick' ] ( function ( ) {
65
- cb ( er ) ;
66
- } ) ;
67
- valid = false ;
68
- }
69
- return valid ;
70
- }
71
-
72
- function writeOrBuffer ( stream , state , chunk , encoding , cb ) {
73
- chunk = decodeChunk ( state , chunk , encoding ) ;
74
- if ( Buffer [ 'isBuffer' ] ( chunk ) )
75
- encoding = 'buffer' ;
76
- var len = state [ 'objectMode' ] ? 1 : chunk [ 'length' ] ;
72
+ function writeOrBuffer ( stream , state , chunk , encoding , cb ) {
73
+ chunk = decodeChunk ( state , chunk , encoding ) ;
74
+ if ( Buffer [ 'isBuffer' ] ( chunk ) )
75
+ encoding = 'buffer' ;
76
+ var len = state [ 'objectMode' ] ? 1 : chunk [ 'length' ] ;
77
77
78
- state [ 'length' ] += len ;
78
+ state [ 'length' ] += len ;
79
79
80
- var ret = state [ 'length' ] < state [ 'highWaterMark' ] ;
81
- // we must ensure that previous needDrain will not be reset to false.
82
- if ( ! ret )
83
- state [ 'needDrain' ] = true ;
80
+ var ret = state [ 'length' ] < state [ 'highWaterMark' ] ;
81
+ // we must ensure that previous needDrain will not be reset to false.
82
+ if ( ! ret )
83
+ state [ 'needDrain' ] = true ;
84
84
85
- if ( state [ 'writing' ] )
86
- state [ 'buffer' ] [ 'push' ] ( new WriteReq ( chunk , encoding , cb ) ) ;
87
- else
88
- doWrite ( stream , state , len , chunk , encoding , cb ) ;
85
+ if ( state [ 'writing' ] )
86
+ state [ 'buffer' ] [ 'push' ] ( new WriteReq ( chunk , encoding , cb ) ) ;
87
+ else
88
+ doWrite ( stream , state , len , chunk , encoding , cb ) ;
89
89
90
- return ret ;
91
- }
92
-
93
- function decodeChunk ( state , chunk , encoding ) {
94
- if ( ! state [ 'objectMode' ] &&
95
- state [ 'decodeStrings' ] !== false &&
96
- typeof chunk === 'string' ) {
97
- chunk = new Buffer ( chunk , encoding ) ;
98
- }
99
- return chunk ;
100
- }
90
+ return ret ;
91
+ }
101
92
102
- /**
103
- * @constructor
104
- */
105
- function WriteReq ( chunk , encoding , cb ) {
106
- this [ 'chunk' ] = chunk ;
107
- this [ 'encoding' ] = encoding ;
108
- this [ 'callback' ] = cb ;
93
+ function decodeChunk ( state , chunk , encoding ) {
94
+ if ( ! state [ 'objectMode' ] &&
95
+ state [ 'decodeStrings' ] !== false &&
96
+ typeof chunk === 'string' ) {
97
+ chunk = new Buffer ( chunk , encoding ) ;
109
98
}
99
+ return chunk ;
100
+ }
110
101
111
- function doWrite ( stream , state , len , chunk , encoding , cb ) {
112
- state [ 'writelen' ] = len ;
113
- state [ 'writecb' ] = cb ;
114
- state [ 'writing' ] = true ;
115
- state [ 'sync '] = true ;
116
- stream [ '_write' ] ( chunk , encoding , state [ 'onwrite' ] ) ;
117
- state [ 'sync '] = false ;
118
- }
102
+ /**
103
+ * @constructor
104
+ */
105
+ function WriteReq ( chunk , encoding , cb ) {
106
+ this [ 'chunk '] = chunk ;
107
+ this [ 'encoding' ] = encoding ;
108
+ this [ 'callback '] = cb ;
109
+ }
119
110
120
- var Duplex = require ( '_stream_duplex' ) ;
121
- Duplex [ 'prototype' ] [ 'write' ] = Writable [ 'prototype' ] [ 'write' ] ;
111
+ function doWrite ( stream , state , len , chunk , encoding , cb ) {
112
+ state [ 'writelen' ] = len ;
113
+ state [ 'writecb' ] = cb ;
114
+ state [ 'writing' ] = true ;
115
+ state [ 'sync' ] = true ;
116
+ stream [ '_write' ] ( chunk , encoding , state [ 'onwrite' ] ) ;
117
+ state [ 'sync' ] = false ;
122
118
}
119
+
120
+ var Duplex = require ( '_stream_duplex' ) ;
121
+ Duplex [ 'prototype' ] [ 'write' ] = Writable [ 'prototype' ] [ 'write' ] ;
123
122
} ) ( ) ;
0 commit comments