[nodejs] fs.read'ing a stream.fd

2012-11-10 Thread Volkan Yazıcı
Hi! I am having trouble while *fs.read*'ing from fd of a stream. For instance, below script produces no outputs. What am I missing? var fs = require("fs"), s = fs.createReadStream(__filename), l = 8192, b = new Buffer(l); s.on("open", function() { fs.read(s.fd, b, 0, l, funct

Re: [nodejs] fs.read'ing a stream.fd

2012-11-10 Thread Martin Cooper
You're mixing up two different approaches to reading the file. When you use fs.createReadStream(), the file will be read automatically as a stream, and you'll start seeing 'data' events with chunks of data as they're read. With this model, you don't do the reading, the stream does it for you. On

Re: [nodejs] fs.read'ing a stream.fd

2012-11-10 Thread Volkan Yazıcı
The problem is some libraries operate on fds to consume the input partially. (E.g., consider parsing the header of a binary file. Library first makes some read()'s, and by looking at the result of those read()'s, maybe some more read()'s too, etc.) OTOH, in my case, the input is piped through s