
Marcus Alanen wrote:
Jonathan Turkanis wrote:
This is a nice idea. IMO, the best way to implement it would be as a filter -- perhaps you could call it a stream_signature_filter. You might use it as follows:
stream_signature_filter f; f.push("GZIP", gzip_decompressor()); f.push("BZh", bzip2_decompressor()); filtering_istreambuf in(f); in.push(file("archive.tar.gz"));
You could then define filters derived from stream_signature_filter that have preset mappings from signatures to filters.
Then again, perhaps the stream_signature_filter should just try out each decompressor in turn, and whichever does not throw an exception should be allowed to continue.
This doesn't generalize well to non-compression filters. Many filters can handle any stream of data without throwing an exception, even if it's not what the user expects.
Please allow it to stream through unknown compression schemes, especially uncompressed files :-)
The way I'd handle this would be to allow signatures to contain wildcard characters, which is necessary anyway for some file formats. Then you could write: stream_signature_filter f; f.push("GZIP", gzip_decompressor()); f.push("BZh", bzip2_decompressor()); f.push("?", identity_filter()); // Wildcard filtering_istreambuf in(f); in.push(file("archive.tar.gz")); This reminds me: despite the algebraic flavor of some of the existing components (null_source, inverse, ...) I never implemented an identity filter.
I'll add this to my list of ideas of 1.34.
Excellent, thank you!
Marcus
Jonathan