KOSAKI Motohiro <kosaki.motohiro / gmail.com> wrote:
> 2011/3/28 Eric Wong <normalperson / yhbt.net>:
> > Issue #4532 has been reported by Eric Wong.
> >
> > ----------------------------------------
> > Feature #4532: [PATCH] add IO#pread and IO#pwrite methods
> > http://redmine.ruby-lang.org/issues/4532
> >
> > Author: Eric Wong
> > Status: Open
> > Priority: Normal
> > Assignee:
> > Category: core
> > Target version: 1.9.x
> >
> >
> > These methods are useful for safe/concurrent file I/O in
> > multi-thread/process environments and also fairly standard
> > nowadays especially in systems supporting pthreads.
> >
> > pread() is already used internally for IO.copy_stream
> 
> Do we really need to introduce new method? Why can't we overload
> IO.read and IO.write?
> too complex?

IO#read and IO#write take userspace buffers into account which
makes no sense with pread/pwrite.

I considered overloading IO#sysread and IO#syswrite, but it would be
hard for users to determine whether offset is supported on their
platform.

New methods means IO.method_defined? and IO#respond_to? to be used.

I'm not a fan of throwing NotImplementedError and faking with lseek() +
read()/write() to be even worse since it loses the atomicity guarantee.

I also considered putting the new methods in File instead of IO, but
sysseek is an IO method so I put it in IO.

> I agree "offset" argument is useful. But I'm not convinced this API
> design is best. The description
> is too quiet.
> 
> Ok, back to meta reviewing comments. All new API proposal need to
> explain why this way
> is best and need to persuade matz.

Thanks again for your time!

-- 
Eric Wong