Class RangesIO
In: lib/ole/ranges_io.rb
Parent: Object

Introduction

RangesIO is a basic class for wrapping another IO object allowing you to arbitrarily reorder slices of the input file by providing a list of ranges. Intended as an initial measure to curb inefficiencies in the Dirent#data method just reading all of a file‘s data in one hit, with no method to stream it.

This class will encapuslate the ranges (corresponding to big or small blocks) of any ole file and thus allow reading/writing directly to the source bytes, in a streamed fashion (so just getting 16 bytes doesn‘t read the whole thing).

In the simplest case it can be used with a single range to provide a limited io to a section of a file.

Limitations

  • No buffering. by design at the moment. Intended for large reads

TODO

On further reflection, this class is something of a joining/optimization of two separate IO classes. a SubfileIO, for providing access to a range within a File as a separate IO object, and a ConcatIO, allowing the presentation of a bunch of io objects as a single unified whole.

I will need such a ConcatIO if I‘m to provide Mime#to_io, a method that will convert a whole mime message into an IO stream, that can be read from. It will just be the concatenation of a series of IO objects, corresponding to headers and boundaries, as StringIO‘s, and SubfileIO objects, coming from the original message proper, or RangesIO as provided by the Attachment#data, that will then get wrapped by Mime in a Base64IO or similar, to get encoded on-the- fly. Thus the attachment, in its plain or encoded form, and the message as a whole never exists as a single string in memory, as it does now. This is a fair bit of work to achieve, but generally useful I believe.

This class isn‘t ole specific, maybe move it to my general ruby stream project.

Methods

<<   close   eof?   gets   inspect   new   open   pos=   ranges=   read   readline   rewind   seek   size=   truncate   write  

External Aliases

pos -> tell

Attributes

io  [R] 
mode  [R] 
pos  [R] 
ranges  [R] 
size  [R] 

Public Class methods

io:the parent io object that we are wrapping.
mode:the mode to use
params:hash of params.
  • :ranges - byte offsets, either:
    1. an array of ranges [1..2, 4..5, 6..8] or
    2. an array of arrays, where the second is length [[1, 1], [4, 1], [6, 2]] for the above (think the way String indexing works)
  • :close_parent - boolean to close parent when this object is closed

NOTE: the ranges can overlap.

add block form. TODO add test for this

Public Instance methods

<<(data)

Alias for write

i can wrap it in a buffered io stream that provides gets, and appropriately handle pos, truncate. mostly added just to past the tests. FIXME

read bytes from file, to a maximum of limit, or all available if unspecified.

readline()

Alias for gets

seek(pos, whence=IO::SEEK_SET)

Alias for pos=

using explicit forward instead of an alias now for overriding. should override truncate.

you may override this call to update @ranges and @size, if applicable.

[Validate]