# Returning to point in file

**URL:** <https://www.ruby-forum.com/t/returning-to-point-in-file/102623>\
**Category:** Ruby\
**Created:** [December 20, 2006, 3:04pm UTC](https://www.ruby-forum.com/t/returning-to-point-in-file/102623 "2006-12-20T15:04:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [December 20, 2006, 3:04pm UTC](https://www.ruby-forum.com/t/returning-to-point-in-file/102623/1 "2006-12-20T15:04:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jspencer78](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f14d63/32.png) [@jspencer78](https://www.ruby-forum.com/u/jspencer78)\
**Post date:** [December 20, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/returning-to-point-in-file/102623/2 "2006-12-20T18:52:05Z")

</div>

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

> 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
