Latch 1.0.1
dotnet add package Latch --version 1.0.1
NuGet\Install-Package Latch -Version 1.0.1
<PackageReference Include="Latch" Version="1.0.1" />
paket add Latch --version 1.0.1
#r "nuget: Latch, 1.0.1"
// Install Latch as a Cake Addin #addin nuget:?package=Latch&version=1.0.1 // Install Latch as a Cake Tool #tool nuget:?package=Latch&version=1.0.1
LatchFileAnalyzer
The latch file analyzer is a binary file checker which determines the actual type of a file by reading the file byte headers which signifies its precise type.
To determine the type of file, the file analyzer provides a static method FileChecker.IsValidFileTypeExtension
which you could pass numerous file extensions which would return a true or false flag which determines if the
provided Stream
or byte[]
is a valid type of any of the extensions provided.
The latch file analyzer also contains methods in the FileChecker which can determine the file type by supplying the bytes read from the file or a stream derived from reading the file.
Limitations
The LatchFileAnalyzer
has a large collection of file headers and types which offers the file checking,
nevertheless, it does not contain all the file types and headers for some file types.
The collection is still growing and we add more as we discover them.
Install
PM> Install-Package Latch -Version 1.0.1
Usage
using System.IO;
using Latch.FileAnalyzer;
using Microsoft.VisualBasic.FileIO;
namespace FileAnalyzer.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
var files = Directory.EnumerateFiles(SpecialDirectories.MyPictures);
foreach (var item in files)
{
var s = new StreamReader(item);
bool isImage = FileChecker.IsValidFileTypeExtension(s.BaseStream, ".png", ".jpg", ".svg");
Console.WriteLine($"{isImage}: {Path.GetFileName(item)}");
}
}
}
}
Or you could pass in any stream or buffer array for it to determine the file type. If the stream or buffer
is not a valid file (just a random stream) the FileChecker
will return false.
Note
This might take longer as the list of headers increases.
using System.IO;
using Latch.FileAnalyzer;
using Microsoft.VisualBasic.FileIO;
namespace FileAnalyzer.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
var files = Directory.EnumerateFiles(SpecialDirectories.MyPictures);
foreach (var item in files)
{
var s = new StreamReader(item);
bool r = FileChecker.GetFileTypeExtension(s.BaseStream, out string ext);
Console.WriteLine($"{r}: {Path.GetFileName(item)}");
}
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1 | 273 | 5/2/2022 |