Greetings gentle monks,

do you know of an existing module that would perform the following :

I need a 'seekable filehandle' wrapper for a filehandle. If the original filehandle is already seekable, e.g. a disk file, it would use the native capability, otherwise it should buffer the contents as the read progresses and support the usual read and tell/seek api; in addition, while using it, I'll sometimes be able to tell it that I will not need to seek before a given position, say $fh->set_seek_start($pos); while a no-op for a real file, this would allow for some memory handling optimisation in the buffered version.

I'd rather not whip my own, so any pointer warmly welcome.

update: this will be used to parse some contents that gets delivered in chunks of unpredictable length. Once a chunk has been successfully parsed I may forget about all contents before its end. The filehande will be read sequentially from start to end except for some backward seek. No forward seek is needed. The filehandle is never written to. The seek is useful for the parsing itself. In addition, if a chunk cannot be parsed I'll seek back to the beginning of the chunk, read forward and try to resync on the beginning of the next one, copy all contents inbetween to an error file to be processed later, and carry on with the new chunk.


In reply to Seekable wrapper for filehandle by Daryn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.