Hi,
Anyone seen some code for compressed IO streams that allow
random access (arbitrary seek)? Along the lines of
razip.sf.net?
It seems to me that ruby-zlib does not provide this. It
has GzipReader and Writer but they don’t give random access?
Any info appreciated,
Karsten
···
–
http://www.fastmail.fm - Same, same, but different
Hi,
Anyone seen some code for compressed IO streams that allow
random access (arbitrary seek)? Along the lines of
razip.sf.net?
Zlib itself doesn’t allow for arbitrary seek. SEEK_END (aka seeking
relative to the end of the stream) isn’t supported, and seeking forward
is basically implemented by reading forward in a tight for() loop.
Here’s what zlib.h has to say about gzseek():
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence));
/*
Sets the starting position for the next gzread or gzwrite on the
given compressed file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in
lseek(2); the value SEEK_END is not supported.
If the file is opened for reading, this function is emulated but
can be extremely slow. If the file is opened for writing, only
forward seeks are supported; gzseek then compresses a sequence of
zeroes up to the new starting position.
gzseek returns the resulting offset location as measured in bytes
from the beginning of the uncompressed stream, or -1 in case of
error, in particular if the file is opened for writing and the new
starting position would be before the current position.
*/
In order to implement truly random access, you’d need to read till the
end of the file, get the length, then rewind the file. Then you could
emulate SEEK_END by rewinding the file, and gzseek()ing forward
file_len - seek_amt. This works, but it’s slooooooow.
···
It seems to me that ruby-zlib does not provide this. It
has GzipReader and Writer but they don’t give random access?
Any info appreciated,
Karsten
–
Paul Duncan pabs@pablotron.org pabs in #gah (OPN IRC)
http://www.pablotron.org/ OpenPGP Key ID: 0x82C29562