It works in object mode, it will break otherwise. Your examples don't use 
objectMode, so there's no garantee this will work.

also, what you are trying to do is easily feasible with 
through<https://npmjs.org/package/through>and 
split <https://npmjs.org/package/split>.

source
  .pipe(split('\n'))
  .pipe(through(function(data) {
    this.queue(JSON.parse(data))
  }))
  .on('data', function (object) {
    //yay my object
  })

On Tuesday, 17 December 2013 02:44:04 UTC+1, Stephen Bartell wrote:
>
> On the writable end, I push a `JSON.stringify`d object.
> On the other reader end, can I expect `chunk` to be `JSON.parse` -able?
>
> When running the code below, it seems like it.  Like, it works and I can't 
> logically make sense of it.  I would expect that if not in objectMode, the 
> reader will need to buffer things until some sentinel pattern is found 
> which will tell me it's safe to call JSON.parse.
>
> Could someone shed some light on why this works and if I can rely on this 
> in practice?
>
> ```
> var Readable = require('stream').Readable;
> var Transform = require('stream').Transform
>
> printer = new Transform()
> printer._transform = function (chunk, enc, next) {
>   console.log(JSON.parse(chunk)) // <- safe to assume I can JSON.parse 
> this?
>   this.push(chunk)
>   next()
> }
>
> var rs = new Readable
> rs.push(JSON.stringify({foo: 'bar'}))
> rs.push(JSON.stringify({foo: 'bar'}))
> rs.push(JSON.stringify({foo: 'bar'}))
> rs.push(null)
>
> rs.pipe(printer)
>
> ```
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to