As Ben said, as long as you're using positional reads (which
fs.ReadStream does) then having multiple readers with the same fd is
totally fine.

However, if you're doing fs.read() without an explicit position, then
the OS will just read from the "current offset" (ie, usually the last
offset + last read length) so that calling read() repeatedly without
an offset will scan through the file as you'd expect.

If you are trying to save yourself fs.open() calls, and reuse fd's
correctly, check out how "st" uses the "fd" module.
https://github.com/isaacs/st and https://github.com/rvagg/node-fd


On Tue, Apr 30, 2013 at 3:21 AM, Fedor Indutny <[email protected]> wrote:
> Because you're reading file from start to end, and position changes at every
> read?
>
> Cheers,
> Fedor.
>
>
> On Tue, Apr 30, 2013 at 2:15 PM, Afshin Mehrabani <[email protected]>
> wrote:
>>
>> Sorry I didn't get it. Why should read an undefined position? or zero?
>>
>> On Tuesday, April 30, 2013 1:12:18 PM UTC+4:30, Ben Noordhuis wrote:
>>>
>>> On Tue, Apr 30, 2013 at 8:08 AM, Afshin Mehrabani <[email protected]>
>>> wrote:
>>> > Just another question guys, what about opening a link to the file and
>>> > then
>>> > use that link in all reads? I mean use fs.open and hold the fd
>>> > parameter in
>>> > a global scope to use it in all other situations.
>>> >
>>> > Will this solution fix the problem?
>>>
>>> Yes, as long as you use positional reads: fs.read() with position >=
>>> 0.  Non-positional reads (position=null or undefined, i.e. read from
>>> current offset) will give unexpected results with multiple readers.
>>
>> --
>> --
>> 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.
>>
>>
>
>
> --
> --
> 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.
>
>

-- 
-- 
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