Skip to content

Pause maybe not working as intended #9

@davebriand

Description

@davebriand

My understanding of pause() with respect to streaming a csv would be to pause the stream at the current record. This would allow async processing to occur before resuming the stream to get the next record.

What's currently happening is the buffer is fully processed before _paused is taken into account.

    var count = 0;
    var csvStream = new csv.createStream({
        endLine : '\n',
        escapeChar : '"',
        enclosedChar: '"'
    })
    var readStream = fs.createReadStream(targetPath)
    csvStream.on('error', function(err){
        console.log(err)
    })
    csvStream.on('data', function(data){
            count++
            console.log('pre pause', count)
            csvStream.pause()
            //I would normally have async code here with a csvStream.resume() in a callback/promise 
        })
    csvStream.on('end', function(){
            console.log("we're done")
            //cb()
        })

    readStream.pipe(csvStream)

I would expect the stream to pause at each record, but it goes through until the end of file (or buffer in this case) before actually entering the paused state.

Is the intended behaviour to process the entire file/buffer before allowing pause() to occur?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions