# Random i/o disk file

**URL:** <https://www.ruby-forum.com/t/random-i-o-disk-file/124997>\
**Category:** Ruby\
**Created:** [January 4, 2008, 1:15pm UTC](https://www.ruby-forum.com/t/random-i-o-disk-file/124997 "2008-01-04T13:15:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [January 4, 2008, 1:15pm UTC](https://www.ruby-forum.com/t/random-i-o-disk-file/124997/1 "2008-01-04T13:15:14Z")

</div>

Am definitely on the steep part of the ruby learning curve. I’ve  
programmed a bit in several other languages. Now I need something like a  
random disk file, so I can have a large hash or something like it  
available for random access. I’ve looked in Programming Ruby II, and the  
Ruby Cookbook. No info there. I then tried to search the arhives at  
[http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml](http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml) - the search  
tool seems not to be working. I then tried to find something with  
Google. No go.

I must be thinking about this wrongly, somehow.

So…how does one handle indexed (random) access to a large file - one  
too large to have in memory? I can’t believe that random/like disk I/O  
is not possible in ruby.

Thanks in advance…

t.

–

```auto
Tom C., MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)

```

---

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [January 4, 2008, 1:37pm UTC](https://www.ruby-forum.com/t/random-i-o-disk-file/124997/2 "2008-01-04T13:37:28Z")

</div>

It works just like in C…

$ echo thisisatest \> test.fil  
$ irb

> > f = File.open(‘test.fil’)  
> > =\> #\<File:test.fil\>
> 
> > f.seek(3, IO::SEEK\_SET)  
> > =\> 0
> 
> > f.read 3  
> > =\> “sis”

/dh

---

<div class="post-metadata">

**Author:** ![tbcox23](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b9bd4f/32.png) [@tbcox23](https://www.ruby-forum.com/u/tbcox23)\
**Post date:** [January 4, 2008, 2:38pm UTC](https://www.ruby-forum.com/t/random-i-o-disk-file/124997/3 "2008-01-04T14:38:24Z")

</div>

Oh, man, I really DID miss something. What great news. You’ve made my  
day, even though it hasn’t really started yet.

Tks,

Tom C.

Denis H. wrote:

> > the search tool seems not to be working. I then tried to find  
> > t.

–

```auto
Tom C., MS MA, LMHC
Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< removed_email_address@domain.invalid >> (email)
<< TomCloyd.com >> (website & psychotherapy weblog)
<< sleightmind.wordpress.com >> (mental health issues weblog)

```
