pause the stream of ops, not the download

the download is buffered in the lineStream so a lot comes out even
after pausing the S3 download.
This commit is contained in:
Brian Gough 2015-09-23 13:38:57 +01:00
parent 847a553344
commit 696a866b67

View file

@ -64,20 +64,21 @@ module.exports = MongoAWS =
ops = [] ops = []
sz = 0 sz = 0
download inputStream = download
.on 'open', (obj) -> .on 'open', (obj) ->
return 1 return 1
.on 'error', (err) -> .on 'error', (err) ->
callback(err) callback(err)
.pipe lineStream .pipe lineStream
.on 'data', (line) ->
inputStream.on 'data', (line) ->
if line.length > 2 if line.length > 2
ops.push(JSON.parse(line)) ops.push(JSON.parse(line))
sz += line.length sz += line.length
if ops.length >= MongoAWS.MAX_COUNT || sz >= MongoAWS.MAX_SIZE if ops.length >= MongoAWS.MAX_COUNT || sz >= MongoAWS.MAX_SIZE
download.pause() inputStream.pause()
MongoAWS.handleBulk ops.slice(0), sz, () -> MongoAWS.handleBulk ops.slice(0), sz, () ->
download.resume() inputStream.resume()
ops.splice(0,ops.length) ops.splice(0,ops.length)
sz = 0 sz = 0
.on 'end', () -> .on 'end', () ->