Skip to content

Commit

Permalink
Merge pull request #10 from clarkis117/6.0.0-alpha1
Browse files Browse the repository at this point in the history
6.0.0 alpha1 prerelease
  • Loading branch information
clarkis117 authored Jan 3, 2018
2 parents 019ff9c + adea3a2 commit 692abcc
Show file tree
Hide file tree
Showing 65 changed files with 1,273 additions and 416 deletions.
36 changes: 26 additions & 10 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,45 @@ $commitHash = $(git rev-parse --short HEAD)
$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""]

echo "build: Package version suffix is $suffix"
echo "build: Build version suffix is $buildSuffix"
echo "build: Build version suffix is $buildSuffix"

foreach ($src in ls src/*) {
Push-Location $src
Push-Location $src

echo "build: Packaging project in $src"

& dotnet build -c Release --version-suffix=$buildSuffix
& dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix --no-build
if($LASTEXITCODE -ne 0) { exit 1 }
& dotnet build -c Release --version-suffix=$buildSuffix

Pop-Location
if($suffix) {
& dotnet pack -c Release --include-source --no-build -o ..\..\artifacts --version-suffix=$suffix
} else {
& dotnet pack -c Release --include-source --no-build -o ..\..\artifacts
}
if($LASTEXITCODE -ne 0) { exit 1 }

Pop-Location
}

foreach ($test in ls test/*.Tests) {
Push-Location $test
Push-Location $test

echo "build: Testing project in $test"

& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }
& dotnet test -c Release
if($LASTEXITCODE -ne 0) { exit 3 }

Pop-Location
}

foreach ($test in ls test/*.PerformanceTests) {
Push-Location $test

echo "build: Building performance test project in $test"

& dotnet build -c Release
if($LASTEXITCODE -ne 0) { exit 2 }

Pop-Location
Pop-Location
}

Pop-Location
9 changes: 8 additions & 1 deletion Mime-Detective.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.4
VisualStudioVersion = 15.0.26430.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{098944FB-C1C9-48BE-AA37-CD3C5C336A84}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A50202E7-0
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mime-Detective", "src\Mime-Detective\Mime-Detective.csproj", "{40608F32-BF6E-4DE4-85AE-EF71C69EF18D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mime-Detective.Benchmarks", "test\Mime-Detective.Benchmarks\Mime-Detective.Benchmarks.csproj", "{7F622459-3B42-4393-A08D-BEB47432628A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,12 +38,17 @@ Global
{40608F32-BF6E-4DE4-85AE-EF71C69EF18D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40608F32-BF6E-4DE4-85AE-EF71C69EF18D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40608F32-BF6E-4DE4-85AE-EF71C69EF18D}.Release|Any CPU.Build.0 = Release|Any CPU
{7F622459-3B42-4393-A08D-BEB47432628A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F622459-3B42-4393-A08D-BEB47432628A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F622459-3B42-4393-A08D-BEB47432628A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F622459-3B42-4393-A08D-BEB47432628A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CB3A9BEA-C247-4FEB-8670-98E3034FC214} = {A50202E7-0386-4EB3-B09C-00EFCAE360F7}
{40608F32-BF6E-4DE4-85AE-EF71C69EF18D} = {17C4E0DE-B863-4A81-B755-62E663D041F1}
{7F622459-3B42-4393-A08D-BEB47432628A} = {A50202E7-0386-4EB3-B09C-00EFCAE360F7}
EndGlobalSection
EndGlobal
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ configuration: Release
install:
- mklink /J Data "test/Mime-Detective.Tests/Data"
- ps: mkdir -Force ".\build\" | Out-Null
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
- ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/v2.1.3/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1"
- ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli"
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0'
- ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 2.1.3'
- ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path"
test: off
build_script:
Expand Down
21 changes: 9 additions & 12 deletions src/Mime-Detective/Extensions/ByteArrayExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static MimeDetective.InputHelpers;

namespace MimeDetective
{
Expand All @@ -13,17 +11,16 @@ public static class ByteArrayExtensions
/// Return null in case when the file type is not identified.
/// Throws Application exception if the file can not be read or does not exist
/// </summary>
/// <remarks>
/// A temp file is written to get a FileInfo from the given bytes.
/// If this is not intended use
///
/// GetFileType(() => bytes);
///
/// </remarks>
/// <param name="file">The FileInfo object.</param>
/// <returns>FileType or null not identified</returns>
public static FileType GetFileType(this byte[] bytes)
=> MimeTypes.GetFileType(() => MimeTypes.ReadHeaderFromByteArray(bytes, MimeTypes.MaxHeaderSize), null, bytes);

{
if (bytes is null)
throw new ArgumentNullException(nameof(bytes));

ReadResult readResult = new ReadResult(bytes, bytes.Length);

return MimeTypes.GetFileType(in readResult);
}
}
}
13 changes: 5 additions & 8 deletions src/Mime-Detective/Extensions/FileInfo/ArchiveExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace MimeDetective
{
using System.IO;
using System.IO;

namespace MimeDetective
{
/// <summary>
/// A set of extension methods for use with document formats.
/// </summary>
Expand All @@ -14,8 +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);

/// <summary>
/// Determines whether the specified file is RAR-archive.
Expand All @@ -24,8 +23,6 @@ public static bool IsZip(this FileInfo fileInfo)
/// <returns>
/// <c>true</c> if the specified file info is RAR; otherwise, <c>false</c>.
/// </returns>
public static bool IsRar(this FileInfo fileInfo)
=> fileInfo.IsType(MimeTypes.RAR);

public static bool IsRar(this FileInfo fileInfo) => fileInfo.IsType(MimeTypes.RAR);
}
}
23 changes: 8 additions & 15 deletions src/Mime-Detective/Extensions/FileInfo/DocumentExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System.IO;
using MimeDetective.Extensions;


namespace MimeDetective
{

/// <summary>
/// A set of extension methods for use with document formats.
/// </summary>
Expand All @@ -17,8 +14,7 @@ public static partial class FileInfoExtensions
/// <returns>
/// <c>true</c> if the specified file is RTF; otherwise, <c>false</c>.
/// </returns>
public static bool IsRtf(this FileInfo fileInfo)
=> fileInfo.IsType(MimeTypes.RTF);
public static bool IsRtf(this FileInfo fileInfo) => fileInfo.IsType(MimeTypes.RTF);

/// <summary>
/// Determines whether the specified file is PDF.
Expand All @@ -27,40 +23,37 @@ public static bool IsRtf(this FileInfo fileInfo)
/// <returns>
/// <c>true</c> if the specified file is PDF; otherwise, <c>false</c>.
/// </returns>
public static bool IsPdf(this FileInfo file)
=> file.IsType(MimeTypes.PDF);

public static bool IsPdf(this FileInfo file) => file.IsType(MimeTypes.PDF);


/// <summary>
/// Determines whether the specified file info is ms-word document file
/// This includes .doc and .docx files
/// </summary>
/// <param name="fileInfo">The file info.</param>
/// <returns>
/// <c>true</c> if the specified file info is doc; otherwise, <c>false</c>.
/// </returns>
public static bool IsWord(this FileInfo fileInfo)
=> (fileInfo.IsType(MimeTypes.WORD) || fileInfo.IsType(MimeTypes.WORDX));

public static bool IsWord(this FileInfo fileInfo) => (fileInfo.IsType(MimeTypes.WORD) || fileInfo.IsType(MimeTypes.WORDX));

/// <summary>
/// Determines whether the specified file info is ms-word document file
/// This includes .ppt and .pptx files
/// </summary>
/// <param name="fileInfo">The file info.</param>
/// <returns>
/// <c>true</c> if the specified file info is doc; otherwise, <c>false</c>.
/// </returns>
public static bool IsPowerPoint(this FileInfo fileInfo)
=> (fileInfo.IsType(MimeTypes.PPT) || fileInfo.IsType(MimeTypes.PPTX));
public static bool IsPowerPoint(this FileInfo fileInfo) => (fileInfo.IsType(MimeTypes.PPT) || fileInfo.IsType(MimeTypes.PPTX));

/// <summary>
/// Determines whether the specified file info is ms-word document file
/// this includes old xls and xlsx files
/// </summary>
/// <param name="fileInfo">The file info.</param>
/// <returns>
/// <c>true</c> if the specified file info is doc; otherwise, <c>false</c>.
/// </returns>
public static bool IsExcel(this FileInfo fileInfo)
=> (fileInfo.IsType(MimeTypes.EXCEL) || fileInfo.IsType(MimeTypes.EXCELX));
public static bool IsExcel(this FileInfo fileInfo) => (fileInfo.IsType(MimeTypes.EXCEL) || fileInfo.IsType(MimeTypes.EXCELX));
}
}
36 changes: 20 additions & 16 deletions src/Mime-Detective/Extensions/FileInfo/FileInfoExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using MimeDetective;
using static MimeDetective.InputHelpers;

namespace MimeDetective
{
Expand All @@ -19,18 +18,26 @@ public static partial class FileInfoExtensions
/// <returns>FileType or null not identified</returns>
public static FileType GetFileType(this FileInfo file)
{
using (var stream = file.OpenRead())
{
return MimeTypes.GetFileType(() => MimeTypes.ReadFileHeader(file, MimeTypes.MaxHeaderSize), stream);
}
if (file is null)
throw new ArgumentNullException(nameof(file));

var stream = file.OpenRead();

ReadResult readResult = ReadFileHeader(stream, MimeTypes.MaxHeaderSize);

return MimeTypes.GetFileType(in readResult);
}

public static async Task<FileType> GetFileTypeAsync(this FileInfo file)
{
using (var stream = file.OpenRead())
{
return await MimeTypes.GetFileTypeAsync(() => MimeTypes.ReadFileHeaderAsync(file, MimeTypes.MaxHeaderSize), stream);
}
if (file is null)
throw new ArgumentNullException(nameof(file));

var stream = file.OpenRead();

ReadResult readResult = await ReadFileHeaderAsync(stream, MimeTypes.MaxHeaderSize);

return MimeTypes.GetFileType(in readResult);
}

/// <summary>
Expand All @@ -45,6 +52,7 @@ public static bool IsFileOfTypes(this FileInfo file, List<FileType> requiredType
{
FileType currentType = file.GetFileType();

//TODO Write a test to check if this null check is correct
if (currentType.Mime == null)
return false;

Expand All @@ -67,9 +75,6 @@ public static bool IsFileOfTypes(this FileInfo file, String CSV)
return file.IsFileOfTypes(providedTypes);
}


#region isType functions

/// <summary>
/// Determines whether the specified file is of provided type
/// </summary>
Expand All @@ -82,6 +87,7 @@ public static bool IsType(this FileInfo file, FileType type)
{
FileType actualType = GetFileType(file);

//TODO Write a test to check if this null check is correct
if (actualType.Mime == null)
return false;

Expand All @@ -93,8 +99,7 @@ public static bool IsType(this FileInfo file, FileType type)
/// </summary>
/// <param name="fileInfo"></param>
/// <returns></returns>
public static bool IsExe(this FileInfo fileInfo)
=> fileInfo.IsType(MimeTypes.DLL_EXE);
public static bool IsExe(this FileInfo fileInfo) => fileInfo.IsType(MimeTypes.DLL_EXE);

/// <summary>
/// Check if the file is Microsoft Installer.
Expand All @@ -109,6 +114,5 @@ public static bool IsMsi(this FileInfo fileInfo)
// MSI has a generic DOCFILE header. Also it matches PPT files
return fileInfo.IsType(MimeTypes.PPT) || fileInfo.IsType(MimeTypes.MSDOC);
}
#endregion
}
}
9 changes: 3 additions & 6 deletions src/Mime-Detective/Extensions/FileInfo/GraphicsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public static partial class FileInfoExtensions
/// <returns>
/// <c>true</c> if the specified file info is PNG; otherwise, <c>false</c>.
/// </returns>
public static bool IsPng(this FileInfo fileInfo)
=> fileInfo.IsType(MimeTypes.PNG);
public static bool IsPng(this FileInfo fileInfo) => fileInfo.IsType(MimeTypes.PNG);

/// <summary>
/// Determines whether the specified file is GIF image
Expand All @@ -24,8 +23,7 @@ public static bool IsPng(this FileInfo fileInfo)
/// <returns>
/// <c>true</c> if the specified file info is GIF; otherwise, <c>false</c>.
/// </returns>
public static bool IsGif(this FileInfo fileInfo)
=> fileInfo.IsType(MimeTypes.GIF);
public static bool IsGif(this FileInfo fileInfo) => fileInfo.IsType(MimeTypes.GIF);

/// <summary>
/// Determines whether the specified file is JPEG image
Expand All @@ -34,7 +32,6 @@ public static bool IsGif(this FileInfo fileInfo)
/// <returns>
/// <c>true</c> if the specified file info is JPEG; otherwise, <c>false</c>.
/// </returns>
public static bool IsJpeg(this FileInfo fileInfo)
=> fileInfo.IsType(MimeTypes.JPEG);
public static bool IsJpeg(this FileInfo fileInfo) => fileInfo.IsType(MimeTypes.JPEG);
}
}
Loading

0 comments on commit 692abcc

Please sign in to comment.