List Archive


Thread Index


From: Mike Crawford <>
Subject: Seeking backwards after reading magic number
Date: Tue, 30 Aug 2016 17:12:51 -0700

Greetings, I just subscribed.  Thank you for your excellent library.

The command-line tool I am developing can accept input in Zip, GZip or BZip2 formats, as well as uncompressed text. To enable that I read the first few bytes from the beginning of the input file; for Zip this is 'PK'.

This works fine if it is a regular file but I'd like to be able to read Zip from standard input; one cannot seek in a pipe. My GZip and BZip support handles this by placing those first few bytes in the input buffers that they use as a source of compressed data, but I don't see a way to do that with Zip.

I'm using the read(2) system call to avoid the overhead of stdio. With stdio, possibly it would work with fseek but I'd like to avoid stdio if I could - the input files can be quite large.

Is there - possibly a hacky - way to place a few bytes in the beginning of Zip's input buffer, as well as to adjust any offset counts?

I hope this makes sense.

Mike Crawford
Portland Software Development and Consulting

One Must Not Trifle With Wizards For It Makes Us Soggy And Hard To Light.

Made by MHonArc.