Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Optimizing research on file type
Message
De
19/01/2016 02:47:13
 
 
À
18/01/2016 15:08:09
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01629800
Message ID:
01629915
Vues:
26
>>(1) make the FileStream a class property
>>(2) add a byte[] Buffer as a class property
>
>I assume the usage of propery would be to avoid declaring the types at each request. Is that correct?
>
>>(3) Add a method IsByteEqual ( int fileOffset, int value)
>>
>>if ( fileOffset +1 > length of the buffer )
>>    read a buffer starting a file offset 0, size = fileOffset +1 rounded to a multiple of 4 k ( or 16 k)
>>
>>return buffer[fileOffset ] ==value
>>
>>You will need to clear the buffer each time you open a new file
>>
>>(4) sample
>>
>>if( IsByteEqual(0, 0x45) andalso IsByteEqual(1, 0x64) )
>>  filetype = something
>>else if if( IsByteEqual(0, 0c80) andalso IsByteEqual(24, 0x88) )
>> filetype = somethingelse
>>.....
>>else
>> filetype = undefined
>>
>
>Thanks, I will see about seeking only at the proper locations.
>
>However, some advanced logic, such as determining a zip file type requires more processing and for particular ones like that, I am not sure if a seek would suffice.

Another approach is to convert the first ??? bytes into a hex string
Then if you have a dictionary ( key = extension, value = list of regex patterns) or (key = extension, value = regex pattern)

You can try every pattern until you find a match

Not saying this is complete but a start http://www.garykessler.net/library/file_sigs.html

And here http://www.filesignatures.net/index.php?page=all
A zip file has 7 possible signatures http://www.filesignatures.net/index.php?search=zip&mode=EXT

Some file types do not have a signature ( like a CSV)

So you may have to end up with taking the file extension ( and test the signature)
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform