Class | RangesIO |
In: |
lib/ole/ranges_io.rb
|
Parent: | Object |
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.
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.
pos | -> | tell |
io | [R] | |
mode | [R] | |
pos | [R] | |
ranges | [R] | |
size | [R] |
io: | the parent io object that we are wrapping. |
mode: | the mode to use |
params: | hash of params. |
NOTE: the ranges can overlap.
using explicit forward instead of an alias now for overriding. should override truncate.