>>(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.htmlAnd here
http://www.filesignatures.net/index.php?page=allA zip file has 7 possible signatures
http://www.filesignatures.net/index.php?search=zip&mode=EXTSome 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