diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2014-04-25 10:44:58 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2014-04-25 10:44:58 +0200 |
commit | eb3771cafb98451116a4f0ec0e7a371800770de1 (patch) | |
tree | 9752ff9c7944b98c7d1c55998d8d89d9f01fd4f7 /src | |
parent | 8d0167bb5aaf1f4d3038c4f5d59ca9fd08edaee2 (diff) | |
download | crawler-eb3771cafb98451116a4f0ec0e7a371800770de1.tar.gz crawler-eb3771cafb98451116a4f0ec0e7a371800770de1.tar.bz2 |
fixed MIME detection using libmagic
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/typedetect/libmagic/LibMagicTypeDetect.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/modules/typedetect/libmagic/LibMagicTypeDetect.cpp b/src/modules/typedetect/libmagic/LibMagicTypeDetect.cpp index cdc8926..4582353 100644 --- a/src/modules/typedetect/libmagic/LibMagicTypeDetect.cpp +++ b/src/modules/typedetect/libmagic/LibMagicTypeDetect.cpp @@ -24,17 +24,19 @@ LibMagicTypeDetect::~LibMagicTypeDetect( ) MIMEType LibMagicTypeDetect::detect( RewindInputStream *s ) { - enum { CHUNKSIZE = 1024 }; + enum { CHUNKSIZE = 65535 }; enum { MAXBUFSIZE = 1024 * 1024 * 16 }; - size_t bufsize = CHUNKSIZE; - char *buf = (char *)malloc( bufsize ); + size_t bufsize = 0; + char *buf = (char *)malloc( CHUNKSIZE ); size_t offset = 0; const char *res = 0; MIMEType type; while( s->good( ) && !s->eof( ) ) { s->read( buf + offset, CHUNKSIZE ); - res = magic_buffer( m_magic, buf, bufsize ); + std::streamsize n = s->gcount( ); + + res = magic_buffer( m_magic, buf, bufsize + n ); if( res != NULL ) { type = MIMEType( res ); @@ -42,13 +44,14 @@ MIMEType LibMagicTypeDetect::detect( RewindInputStream *s ) break; } } + + bufsize += CHUNKSIZE; + offset += CHUNKSIZE; if( bufsize > MAXBUFSIZE ) { break; } - - bufsize += CHUNKSIZE; - offset += CHUNKSIZE; + buf = (char *)realloc( buf, bufsize ); } |