dominictarr / split

MIT License
347 stars 39 forks source link

Suppress last empty line #13

Closed moll closed 9 years ago

moll commented 9 years ago

Hey,

I see https://github.com/dominictarr/split/commit/078cfb4213c43f106fc439fb4358f95bef3a8bf6 fixes someones wish to get the last empty line (or whatever concept they're using to split). That's the same behavior I personally don't want as I'm using Split for converting a stream of delimited records to individual objects.

How would I suppress the last empty string from being emitted? Or is Split not the right stream module for that case?

Thanks!

PS. The comparison to null seems pointless given that soFar is initialized to an empty string at the top of the file ensuring it can never be anything other than a string.

dominictarr commented 9 years ago

If you make a pull request that adds an option to drop the trailing empty line I will merge it.

moll commented 9 years ago

Fair enough. But I can't promise anything soon as just using an older version was an easier fix. :-)

siboulet commented 9 years ago

This also breaks using the transform function for new line delimited JSON when the last line is empty.

SyntaxError: Unexpected end of input
    at parse (native)
    at emit (x/node_modules/split/index.js:27:17)
    at Stream.<anonymous> (x/node_modules/split/index.js:59:7)
    at _end (x/node_modules/split/node_modules/through/index.js:65:9)
    at Stream.stream.end (x/node_modules/split/node_modules/through/index.js:74:5)
    at Socket.onend (_stream_readable.js:505:10)
    at Socket.g (events.js:199:16)
    at Socket.emit (events.js:129:20)
    at _stream_readable.js:908:16
    at process._tickCallback (node.js:355:11)
raine commented 9 years ago

split2 doesn't exhibit this behavior.