File tree 2 files changed +39
-1
lines changed
2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 183
183
this . _parser = new SAXParser ( strict , opt )
184
184
this . writable = true
185
185
this . readable = true
186
+ this . paused = false
186
187
187
188
var me = this
188
189
238
239
239
240
this . _parser . write ( data . toString ( ) )
240
241
this . emit ( 'data' , data )
241
- return true
242
+ return ! this . paused
242
243
}
243
244
244
245
SAXStream . prototype . end = function ( chunk ) {
249
250
return true
250
251
}
251
252
253
+ SAXStream . prototype . pause = function ( ) {
254
+ this . paused = true
255
+ }
256
+
257
+ SAXStream . prototype . resume = function ( ) {
258
+ if ( this . paused ) {
259
+ this . paused = false
260
+ this . emit ( 'drain' )
261
+ }
262
+ }
263
+
252
264
SAXStream . prototype . on = function ( ev , handler ) {
253
265
var me = this
254
266
if ( ! me . _parser [ 'on' + ev ] && streamWraps . indexOf ( ev ) !== - 1 ) {
Original file line number Diff line number Diff line change
1
+ var tap = require ( 'tap' )
2
+
3
+ // pausable stream that will understand and handle push returning false
4
+ var Readable = require ( 'stream' ) . Readable
5
+ var inputStream = new Readable ( )
6
+ var saxStream = require ( '../lib/sax' ) . createStream ( )
7
+
8
+ var paused = true
9
+ saxStream . pause ( )
10
+
11
+ saxStream . on ( 'data' , function ( ) {
12
+ tap . equal ( false , paused , 'Received data while paused' )
13
+ } )
14
+
15
+ inputStream . pipe ( saxStream )
16
+
17
+ inputStream . push ( '<test><a>' )
18
+ inputStream . push ( '</a><b>' )
19
+ inputStream . push ( '</b><c>' )
20
+ inputStream . push ( '</c>' )
21
+ inputStream . push ( '<d>' )
22
+ inputStream . push ( '</d></test>' )
23
+ inputStream . push ( null )
24
+
25
+ paused = false
26
+ saxStream . resume ( )
You can’t perform that action at this time.
0 commit comments