C#.net identify zip file

前端 未结 6 528
栀梦
栀梦 2020-12-03 10:45

I am currently using the SharpZip api to handle my zip file entries. It works splendid for zipping and unzipping. Though, I am having trouble identifying if a file is a zip

6条回答
  •  忘掉有多难
    2020-12-03 11:33

    You can either:

    • Use a try-catch structure and try to read the structure of a potential zip file
    • Parse the file header to see if it is a zip file

    ZIP files always start with 0x04034b50 as its first 4 bytes ( http://en.wikipedia.org/wiki/Zip_(file_format)#File_headers )

提交回复
热议问题