Namazu-devel-ja(旧)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: File-MMagic (Re: ichitaro)
knok@xxxxxxxxxxxxx (NOKUBI Takatsugu) wrote:
> あ、わかりました。checktype_filename() だと、binary に見えないものは
>即座に text/plain と判別して、それ移行のチェックをしないためだと思いま
>す。
>
># そうしたのには、なにか理由があった気が...
>
> checktype_filehandle() なら正しく判別されると思います。
駄目みたいです。
% File *(.)
Makefile: text/plain
Makefile.am: text/plain
Makefile.in: text/plain
acrobat3.pdf: application/pdf
acrobat4.pdf: application/pdf
d20000220.hnf: text/plain
excel97.xls: text/plain
html.html: text/html
ichitaro4.jsw: application/octet-stream
ichitaro5.jaw: application/octet-stream
ichitaro6.jbw: application/octet-stream
mail-multipart.txt: message/rfc822
mail.txt: message/rfc822
man.1: text/x-roff
msg00000.html: text/html
plain.txt: text/plain
plain.txt.Z: application/x-compress
plain.txt.bz2: application/x-bzip2
plain.txt.gz: application/x-gzip
rfc0000.txt: text/plain
tex.tex: text/plain
word6.doc: text/plain
word95.doc: text/plain
word97.doc: text/plain
word98.doc: text/plain
% cat =File
#! /usr/local/bin/perl -w
use strict;
use File::MMagic;
use FileHandle;
my $magic = new File::MMagic;
for my $file (@ARGV) {
my $fh = new FileHandle;
$fh->open($file) || die "$file: $!";
my $mtype = $magic->checktype_filehandle($fh);
printf "$file: $mtype\n";
}
-- Satoru Takabayashi