dmdz

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Mar 18 13:02:20 PDT 2010


On 03/18/2010 02:49 PM, Walter Bright wrote:
> Andrei Alexandrescu wrote:
>> Heh, incidentally I just needed a tar reader a few days ago, so I
>> wrote an embryo of a base class etc. I'll add it soon.
>>
>> The basic interface is:
>>
>> (a) open the archive
>>
>> (b) get an input range for it. The range iterates over archive entries.
>>
>> (c) You can look at archive info, and if you want to extract you can
>> get a .byChunk() range to extract it. That's also an input range.
>>
>> For now I'm only concerned with reading... writing needs to be added.
>
> That's great, but I only suggest that this not be added to Phobos until
> a generic archive interface is also added. That way, we can constantly
> add support for new archive formats without requiring users to change
> their code.

Yah.

> Some suggestions for that:
>
> 1. The archive type should be represented by a string literal, not an
> enum. This way, users can add other archive types without having to
> touch the Phobos source code.
> 2. The reader should auto-detect the archive type based on the file
> contents, not the file name, and then call the appropriate factory method.

The archive type should be a D class inheriting ArchiveReader, so no 
enum and no string need be involved. The rest is a matter of registry - 
a new archiver registers itself into a database of archivers that maps 
file header data to (pointers to) factory methods. Typical file 
extensions should help, too, because they'd ease matching.

Reading the file header (e.g. first 512 bytes) and then matching against 
archive signatures is, I think, a very nice touch. (I was only thinking 
of matching by file name.) There is a mild complication - you can't 
close and reopen the archive, so you need to pass those 512 bytes to the 
archiver along with the rest of the stream. This is because the stream 
may not be rewindable, as is the case with pipes.

Sounds great!


Andrei



More information about the Digitalmars-d mailing list