file-backed array of classes?

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default file-backed array of classes?


    I was looking at prototyping a write once file service, a bit like
    Plan9s Venti system. I delete files a lot :)
    As usual, my grand designs are thwarted by the basics...

    I'm at the 'get the unit tests of the simplest possible implementation to
    pass' stage, and need something like an append-only file of fixed
    size records (data blocks). Have we got classes or methods to do
    record-based file IO? I dont mind reinventing a wheel otherwise.

    Next problem (I learned to never look more than 1 problem ahead or I
    never start anything). I need an index that gets dynamically updated as
    the record file is written to.

    The ideal solution would be a hash that was backed by a file somehow-
    then I realised I could implement the data blocks themselves
    the same way.

    I looked through pickAxe and RAA for these two and found a lot of SQL
    persistence APIs, but that feels like overkill....

    Does anyone know of a more lightweight solution?
    --
    I don't care who does the electing as long as I get to do the
    nominating.
    -- Boss Tweed
    Rasputin :: Jack of All Trades - Master of Nuns

    Rasputin Guest

  2. Similar Questions and Discussions

    1. Generating classes from an .xsd file
      Hello, I am working on a VB.NET web service that will be used to send and receive job openings. I found a site called "hr-xml consortium" ...
    2. Databinding array of custom classes to DataGrid
      I can't seem to bind an array of custom classes to my DataGrid. I get the following error "A field or property with the name 'dcAbbreviation' was...
    3. Array Problem with custom classes
      I have tried to store instances of a custom class in an array. When I retrieve the object actionScript seems to have forgotten what type of object...
    4. Classes & 2 Dim Array Help
      I need to do some screen scraping and I am playing with a table object. I would like to iterate through a table in the syntax of $table->tr->td or...
    5. Restoring win98 backed up files
      I have just up-graded from win98 to windows XP. I did my back up before upgrade to a external hard drive on a fire wire card. After the upgrade...
  3. #2

    Default Re: file-backed array of classes?


    "Rasputin" <rasputin@idoru.mine.nu> schrieb im Newsbeitrag
    news:20031114115944.GA18331@lb.tenfour...
    >
    > I was looking at prototyping a write once file service, a bit like
    > Plan9s Venti system. I delete files a lot :)
    > As usual, my grand designs are thwarted by the basics...
    >
    > I'm at the 'get the unit tests of the simplest possible implementation
    to
    > pass' stage, and need something like an append-only file of fixed
    > size records (data blocks). Have we got classes or methods to do
    > record-based file IO? I dont mind reinventing a wheel otherwise.
    A typical solution might involve IO with binary mode with Array#pack and
    String.unpack. Then you'll have to do the byte layout and record size
    fixing yourself.

    Or you can use Marshalling for this: define a class and marshal instances
    one at a time into the file:

    st = Struct.new( "FooRecord", :name, :age )
    records = (1..10).map{|i| st.new("hello", i)}

    File.open("foo.bin", "wb") do |io|
    records.each do |rec|
    Marshal.dump(rec, io)
    end
    end

    File.open("foo.bin", "rb") do |io|
    until io.eof?
    obj = Marshal.load(io)
    puts obj
    end
    end

    Of courese you can marshal a complete array, too. But then, all instances
    are loaded at once and with the approach above you can read one record at
    a time, thus navigating (not very efficient though).
    > Next problem (I learned to never look more than 1 problem ahead or I
    > never start anything). I need an index that gets dynamically updated as
    > the record file is written to.
    If the dataset will grow not too big, you could use a Hash and Marshal
    that in a file...
    > The ideal solution would be a hash that was backed by a file somehow-
    > then I realised I could implement the data blocks themselves
    > the same way.
    >
    > I looked through pickAxe and RAA for these two and found a lot of SQL
    > persistence APIs, but that feels like overkill....
    >
    > Does anyone know of a more lightweight solution?
    Not perfectly what you are looking for but maybe some ideas to play
    with...

    robert

    Robert Klemme Guest

  4. #3

    Default Re: file-backed array of classes?

    Have you considered PStore in the standard library?


    ----- Original Message -----
    From: "Rasputin" <rasputin@idoru.mine.nu>
    To: "ruby-talk ML" <ruby-talk@ruby-lang.org>
    Sent: Friday, November 14, 2003 11:59 AM
    Subject: file-backed array of classes?

    >
    > I was looking at prototyping a write once file service, a bit like
    > Plan9s Venti system. I delete files a lot :)
    > As usual, my grand designs are thwarted by the basics...
    >
    > I'm at the 'get the unit tests of the simplest possible implementation to
    > pass' stage, and need something like an append-only file of fixed
    > size records (data blocks). Have we got classes or methods to do
    > record-based file IO? I dont mind reinventing a wheel otherwise.
    >
    > Next problem (I learned to never look more than 1 problem ahead or I
    > never start anything). I need an index that gets dynamically updated as
    > the record file is written to.
    >
    > The ideal solution would be a hash that was backed by a file somehow-
    > then I realised I could implement the data blocks themselves
    > the same way.
    >
    > I looked through pickAxe and RAA for these two and found a lot of SQL
    > persistence APIs, but that feels like overkill....
    >
    > Does anyone know of a more lightweight solution?
    > --
    > I don't care who does the electing as long as I get to do the
    > nominating.
    > -- Boss Tweed
    > Rasputin :: Jack of All Trades - Master of Nuns
    >
    Neil Mc Laughlin Guest

  5. #4

    Default Re: file-backed array of classes?

    On Fri, 14 Nov 2003 20:59:47 +0900, Rasputin wrote:
    > I'm at the 'get the unit tests of the simplest possible implementation to
    > pass' stage, and need something like an append-only file of fixed
    > size records (data blocks). Have we got classes or methods to do
    > record-based file IO? I dont mind reinventing a wheel otherwise.
    record-based file IO, can you explain further?

    > Next problem (I learned to never look more than 1 problem ahead or I
    > never start anything). I need an index that gets dynamically updated as
    > the record file is written to.
    I have written a robust-iterator primitive, where iterators gets notified
    when somebody insert/delete data, so they iterator keeps pointing at the
    same position.

    [url]http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/projects/experimental/iterator2/?cvsroot=aeditor[/url]

    --
    Simon Strandgaard

    Simon Strandgaard Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139