Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
fs.read'ing a stream.fd
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Volkan Yazıcı  
View profile  
 More options Nov 10 2012, 3:00 pm
From: Volkan Yazıcı <volkan.yaz...@gmail.com>
Date: Sat, 10 Nov 2012 12:00:40 -0800 (PST)
Local: Sat, Nov 10 2012 3:00 pm
Subject: fs.read'ing a stream.fd

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, function (err, nbytes) {
                console.log(
                        "err: " + err + ", " +
                        "nbytes: " + nbytes + ", " +
                        "buf: " + b.toString(0, nbytes));
        });});


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Martin Cooper  
View profile  
 More options Nov 10 2012, 3:57 pm
From: Martin Cooper <mfncoo...@gmail.com>
Date: Sat, 10 Nov 2012 12:56:40 -0800
Local: Sat, Nov 10 2012 3:56 pm
Subject: Re: [nodejs] fs.read'ing a stream.fd

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 the other hand, if you want to read the file manually, you'll need to
open it using fs.open() first. Then you can use fs.read() calls to get the
data.

I'd recommend the stream approach, unless there's some reason you can't do
that.

--
Martin Cooper

On Sat, Nov 10, 2012 at 12:00 PM, Volkan Yazıcı <volkan.yaz...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Volkan Yazıcı  
View profile  
 More options Nov 10 2012, 4:07 pm
From: Volkan Yazıcı <volkan.yaz...@gmail.com>
Date: Sat, 10 Nov 2012 13:07:46 -0800 (PST)
Local: Sat, Nov 10 2012 4:07 pm
Subject: Re: [nodejs] fs.read'ing a stream.fd

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 some other library which provides you a stream. And I need to pipe
that stream to some other library that asks for a fd. Any recommendations?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »