------ art_32454_29969261.1151930924346 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 7/3/06, transfire / gmail.com <transfire / gmail.com> wrote: > > > transfire / gmail.com wrote: > > Using Archive::Tar:Minitar, is there any way to quickly check if a file > > is a tar file or not? > > To answer my own question, sadly, "no": > > Magic bytes > None. > However, identification of tar files is not limited to looking at > the file extension. Each tar archive entry header also stores a > checksum on itself. Thus, reading the first 512 bytes of a potential > tar file, creating that checksum and comparing it to the stored > checksum will tell if the file really is in tar format. > > That's too complex for efficent checking. OTOH, Luckly gzips are easy > to identify. Not tested but basically: Might it be sufficent for your purpose to check if the first 100 bytes are of the form ASCI+\0* ? Sorry I do not have a uft8 fs handy to see if the ASCI+ contraint can be easily checked in that case. Cheers Robert class File > # Is a file a gzip file? > def self.gzip?( file ) > File.open(file,'rb') { |f| > return false unless f.getc == 0x1f > return false unless f.getc == 0x8b > } > end > end > > Might be worth adding to Zlib (assuming it'snot already there --I > didn't see it). > > T. > > > -- Deux choses sont infinies : l'univers et la bóŐise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------ art_32454_29969261.1151930924346--