Reputation: 99
If I have a FileStream how can I check if it's from a ZipArchive ? Now I use a try catch statement that throw a
'System.IO.InvalidDataException: 'End of Central Directory record could not be found.'
if the stream is not from a ZipArchive.
try
{
ZipArchive za = new ZipArchive(fIleStream, ZipArchiveMode.Read);
...
}
catch (Exception e)
{
...
}
Upvotes: 1
Views: 793
Reputation: 492
You could sniff the first two bytes of the stream to see if it matches the zip signature.
As described here https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
Should be 0x504b to be zip data.
Upvotes: 3