[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Returning to point in file

James Smith

12/20/2006 2:04:00 PM

Hello,

I am opening a file and reading from it. I need to leave the file and
then return to the position that i finished reading at.

OK, so i can get the exact position in bytes using pipe.pos

However when i return to the file i then need to jump back to this
position, i can't seem to so this using ios.seek, is there a way to do
this?

The final resort i suppose would be to write something to the file to
mark the last position of reading and then when returning read and do
nothing untill you hit this spot.. any other ideas?

Thanks, Jamie

--
Posted via http://www.ruby-....

1 Answer

Ken Bloom

12/20/2006 3:26:00 PM

0

On Wed, 20 Dec 2006 23:04:16 +0900, James Smith wrote:

> Hello,
>
> I am opening a file and reading from it. I need to leave the file and
> then return to the position that i finished reading at.
>
> OK, so i can get the exact position in bytes using pipe.pos
>
> However when i return to the file i then need to jump back to this
> position, i can't seem to so this using ios.seek, is there a way to do
> this?
>
> The final resort i suppose would be to write something to the file to
> mark the last position of reading and then when returning read and do
> nothing untill you hit this spot.. any other ideas?

Works just fine for me, although I had to seek to 0 to begin with for it
to work.:

irb(main):001:0> f=open("/dev/full","r")
=> #<File:/dev/full>
irb(main):002:0> f.read(120)
=> 120 null bytes
irb(main):003:0> f.pos
Errno::EINVAL: Invalid argument - /dev/full
from (irb):3:in `pos'
from (irb):3
from :0
irb(main):005:0> f.seek 400
=> 0
irb(main):006:0> f.pos
=> 400
irb(main):007:0> f.seek 0
=> 0
irb(main):008:0> f.read 120
=> 120 null bytes
irb(main):009:0> f.pos
=> 120


--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...