Google Groups

Re: [node-dev] Adding in flock/seek/utime

Matt Sergeant Aug 31, 2011 8:49 PM
Posted in group: nodejs-dev
OK, so seriously guys - is this something waiting for a patch to happen (let's just say flock and seek), or should I let the core devs do it their way?

On Mon, Aug 29, 2011 at 11:06 PM, Ryan Dahl <> wrote:
On Mon, Aug 29, 2011 at 6:55 PM, Thomas Shinnick <> wrote:
> On Monday, August 29, 2011 8:19:03 PM UTC-5, Ryan Dahl wrote:
>> > - seek: yes. Same as flock. I admit I'm kinda surprised that we don't
>> > already have a lseek binding.
>> No need for seek. We have pread, pwrite.
> This has been said before.  If it is the official answer, fine, but then
> non-trivial patches are needed to actually *use* pread/pwrite in a couple
> places they are not used right now.  I don't remember exactly, but I think
> it is some stream code that doesn't track the "current file location" so
> that pread/pwrite _can_ be used.  That may have been partially fixed for one
> path recently...?

A patch for a seek method to fs.ReadStream and fs.WriteStream would be
acceptable. It's not very difficult.

> The problem is that
>   - seek() is not provided, so you can't start I/O at the 'correct' file
> offset, and
>   - streams (and I think other code) do not maintain file offset information
> to allow pwrite/pread to be used
> so that saying "we have pread/pwrite" is not enough.  Not enough to actually
> provide the functionality wanted.
> While it has also been said before "well, you can track the file offsets
> yourself and do your own reading/writing" that kinda says "yeah, well, when
> streams can't use node APIs well, write your own."  Feels somehow wrong...
> BTW: have you looked at the pread/pwrite code in EIO?  Guess how it gets
> done in some situations.  Yup, lseek() (and quite ugly it is too)  And
> apparently noticed at one point -

It's just for compatibility with systems that don't have pread/pwrite.