Skip to content

Commit

Permalink
Add support for Empty zip file (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyDez authored and clarkis117 committed Oct 24, 2018
1 parent aa80578 commit f643dee
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static partial class FileInfoExtensions
/// <returns>
/// <c>true</c> if the specified file info is zip; otherwise, <c>false</c>.
/// </returns>
public static bool IsZip(this FileInfo fileInfo) => fileInfo.IsType(MimeTypes.ZIP);
public static bool IsZip(this FileInfo fileInfo) => fileInfo.IsType(MimeTypes.ZIP) || fileInfo.IsType(MimeTypes.ZIP_EMPTY);

/// <summary>
/// Determines whether the specified file is RAR-archive.
Expand Down
3 changes: 2 additions & 1 deletion src/Mime-Detective/MimeTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public static class MimeTypes
public readonly static FileType ZIP_7z = new FileType(new byte?[] { 0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C }, "7z", "application/x-compressed");

public readonly static FileType ZIP = new FileType(new byte?[] { 0x50, 0x4B, 0x03, 0x04 }, "zip", "application/x-compressed");
public readonly static FileType ZIP_EMPTY = new FileType(new byte?[] { 0x50, 0x4B, 0x05, 0x06 }, "zip", "application/x-compressed");
public readonly static FileType RAR = new FileType(new byte?[] { 0x52, 0x61, 0x72, 0x21 }, "rar", "application/x-compressed");
public readonly static FileType DLL_EXE = new FileType(new byte?[] { 0x4D, 0x5A }, "dll,exe", "application/octet-stream");

Expand Down Expand Up @@ -212,7 +213,7 @@ EML is also used by Outlook Express and QuickMail.
//EVTX Windows Vista event log file
public readonly static FileType ELF = new FileType(new byte?[] { 0x45, 0x6C, 0x66, 0x46, 0x69, 0x6C, 0x65, 0x00 }, "elf", "text/plain");

public static readonly FileType[] Types = new FileType[] { PDF, JPEG, ZIP, RAR, RTF, PNG, GIF, DLL_EXE, MS_OFFICE,
public static readonly FileType[] Types = new FileType[] { PDF, JPEG, ZIP, ZIP_EMPTY, RAR, RTF, PNG, GIF, DLL_EXE, MS_OFFICE,
BMP, DLL_EXE, ZIP_7z, GZ_TGZ, TAR_ZH, TAR_ZV, OGG, ICO, XML, DWG, LIB_COFF, PST, PSD, BZ2,
AES, SKR, SKR_2, PKR, EML_FROM, ELF, TXT_UTF8, TXT_UTF16_BE, TXT_UTF16_LE, TXT_UTF32_BE, TXT_UTF32_LE,
Mp3ID3, Wav, Flac, MIDI,
Expand Down
Binary file not shown.
Binary file added test/Mime-Detective.Tests/Data/Zip/emptyZip.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public void DefaultConstructor()
[InlineData("./Data/Documents/DocxWord2016.docx", "docx")]
[InlineData("./Data/Zip/Images.zip", "zip")]
[InlineData("./Data/Zip/ImagesBy7zip.zip", "zip")]
[InlineData("./Data/Zip/EmptiedBy7zip.zip", "zip")]
[InlineData("./Data/Zip/emptyZip.zip", "zip")]
public async Task Search(string path, string ext)
{
var analyzer = new ZipFileAnalyzer();
Expand Down
12 changes: 12 additions & 0 deletions test/Mime-Detective.Tests/Tests/Zip/CommonFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public async Task IsZip(string file)
await AssertIsType(fileInfo, MimeTypes.ZIP);
}

[Theory]
[InlineData("emptyZip")]
[InlineData("EmptiedBy7zip")]
public async Task IsEmptyZip(string file)
{
var fileInfo = GetFileInfo(dataPath, file, ".zip");

Assert.True(fileInfo.IsZip());

await AssertIsType(fileInfo, MimeTypes.ZIP_EMPTY);
}

[Fact]
public async Task Is7zip()
{
Expand Down

0 comments on commit f643dee

Please sign in to comment.