New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property 'read' of object #<Socket> is not a function #55

Closed
giacecco opened this Issue Apr 11, 2014 · 7 comments

Comments

Projects
None yet
2 participants
@giacecco

giacecco commented Apr 11, 2014

The simple script below fails reading a text file with one JavaScript object per line. Why?

var fs = require("fs"),
    es = require("event-stream");
es.pipeline(
    fs.createReadStream("./file.txt", {flags: 'r'}),
    es.split('\n'),
    process.stdout
);

Some sample content from the input file is below:

{"JsonTimetableV1":{"classification":"public","timestamp":1397171668,"owner":"Network Rail","Sender":{"organisation":"Rockshore","application":"NTROD","component":"SCHEDULE"},"Metadata":{"type":"full","sequence":666}}}
{"JsonAssociationV1":{"transaction_type":"Create","main_train_uid":"W20936","assoc_train_uid":"W20815","assoc_start_date":"2013-12-14T00:00:00Z","assoc_end_date":"2014-05-17T00:00:00Z","assoc_days":"0000010","category":"NP","date_indicator":"S","location":"RAMSGTE","base_location_suffix":null,"assoc_location_suffix":null,"diagram_type":"T","CIF_stp_indicator":"P"}}
(...)

The error is:

_stream_readable.js:745
    while (!paused && (null !== (c = stream.read())))
                                            ^
TypeError: Property 'read' of object #<Socket> is not a function
    at Socket.<anonymous> (_stream_readable.js:745:45)
    at Socket.EventEmitter.emit (events.js:92:17)
    at emitDataEvents (_stream_readable.js:771:10)
    at Socket.Readable.on (_stream_readable.js:692:5)
    at proxyStream (/Users/giacecco/Projects/stomp-test/node_modules/event-stream/node_modules/duplexer/index.js:65:16)
    at Array.forEach (native)
    at forEach (/Users/giacecco/Projects/stomp-test/node_modules/event-stream/node_modules/duplexer/index.js:11:20)
    at duplex (/Users/giacecco/Projects/stomp-test/node_modules/event-stream/node_modules/duplexer/index.js:27:5)
    at Object.module.exports (/Users/giacecco/Projects/stomp-test/node_modules/event-stream/node_modules/stream-combiner/index.js:8:17)
    at Object.<anonymous> (/Users/giacecco/Projects/stomp-test/test3.js:4:4)

I am using node v0.10.26. Thanks,

Giacecco

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Apr 12, 2014

just use

    fs.createReadStream("./file.txt", {flags: 'r'})
     .pipe(es.split('\n'))
    .pipe(process.stdout)

instead of pipeline.

@giacecco

This comment has been minimized.

giacecco commented Apr 12, 2014

That works, but why didn't it work the other way?

@giacecco giacecco closed this Apr 12, 2014

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Apr 13, 2014

Something to do with streams2. I should probably just remove es.pipeline from the docs. I've never used it since node was 0.4 (you needed that then, but in 0.6 they made pipe chainable)

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Apr 13, 2014

heh, you must be using an old version of event-stream anyway! look at this: https://github.com/dominictarr/event-stream/blob/master/index.js#L301-L303

@giacecco

This comment has been minimized.

giacecco commented Apr 13, 2014

Actually, that pattern is in the very first example in the docs! https://github.com/dominictarr/event-stream/blob/master/readme.markdown

@dominictarr

This comment has been minimized.

Owner

dominictarr commented Apr 13, 2014

oh my! I'm glad no body does that!
Okay I've updated the docs to use new idioms.

@giacecco

This comment has been minimized.

giacecco commented Apr 13, 2014

Thanks :-)

On 13 Apr 2014, at 11:34, Dominic Tarr notifications@github.com wrote:

oh my! I'm glad no body does that!
Okay I've updated the docs to use new idioms.


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment