Daryn has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Seekable wrapper for filehandle
by sgifford (Prior) on Apr 12, 2006 at 14:01 UTC | |
|
Re: Seekable wrapper for filehandle
by japhy (Canon) on Apr 12, 2006 at 12:27 UTC |