Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Empty zip file #27

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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