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...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Returning to point in file
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password