File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,8 @@ const WRITE_BACKPRESSURE_STATUS = WRITE_UNDRAINED | DESTROY_STATUS | WRITE_FINIS
112
112
const WRITE_UPDATE_SYNC_STATUS = WRITE_UPDATING | OPEN_STATUS | WRITE_NEXT_TICK | WRITE_PRIMARY
113
113
const WRITE_DROP_DATA = WRITE_FINISHING | WRITE_DONE | DESTROY_STATUS
114
114
115
+ const DISTURBED_STATUS = OPEN_STATUS | READ_RESUMED_READ_AHEAD | WRITE_QUEUED
116
+
115
117
const asyncIterator = Symbol . asyncIterator || Symbol ( 'asyncIterator' )
116
118
117
119
class WritableState {
@@ -1134,6 +1136,10 @@ function isReadStreamx (stream) {
1134
1136
return isStreamx ( stream ) && stream . readable
1135
1137
}
1136
1138
1139
+ function isDisturbed ( stream ) {
1140
+ return ( stream . _duplexState & DISTURBED_STATUS ) !== OPENING
1141
+ }
1142
+
1137
1143
function isTypedArray ( data ) {
1138
1144
return typeof data === 'object' && data !== null && typeof data . byteLength === 'number'
1139
1145
}
@@ -1157,6 +1163,7 @@ module.exports = {
1157
1163
pipelinePromise,
1158
1164
isStream,
1159
1165
isStreamx,
1166
+ isDisturbed,
1160
1167
isEnded,
1161
1168
isFinished,
1162
1169
getStreamError,
Original file line number Diff line number Diff line change 1
1
const test = require ( 'brittle' )
2
2
const b4a = require ( 'b4a' )
3
- const { Readable } = require ( '../' )
3
+ const { Readable, isDisturbed } = require ( '../' )
4
4
5
5
test ( 'ondata' , function ( t ) {
6
6
t . plan ( 4 )
@@ -403,6 +403,16 @@ test('setEncoding empty string', async function (t) {
403
403
}
404
404
} )
405
405
406
+ test ( 'is disturbed' , function ( t ) {
407
+ const r = new Readable ( )
408
+
409
+ t . not ( isDisturbed ( r ) )
410
+
411
+ r . resume ( )
412
+
413
+ t . ok ( isDisturbed ( r ) )
414
+ } )
415
+
406
416
function nextImmediate ( ) {
407
417
return new Promise ( resolve => setImmediate ( resolve ) )
408
418
}
You can’t perform that action at this time.
0 commit comments