-
Notifications
You must be signed in to change notification settings - Fork 30
How to use?
Aleksander J. Mitev edited this page Mar 10, 2020
·
1 revision
In this page you will find how easy is to recognize type of a file with FileTypeChecker.
using var fileStream = File.OpenRead(filePath);
var isRecognizableType = FileTypeValidator.IsTypeRecognizable(fileStream);
using var fileStream = File.OpenRead(filePath);
var isRecognizableType = FileTypeValidator.IsTypeRecognizable(fileStream);
if (!isRecognizableType)
{
throw new InvalidDataException("Invalid file type!");
}
IFileType fileType = FileTypeValidator.GetFileType(fileStream);
using FileTypeChecker.Types;
bool isBitmap = FileTypeValidator.Is<Bitmap>(fileStream);
Or
using FileTypeChecker.Types;
using FileTypeChecker.Extensions;
bool isBitmap = fileStream.Is<Bitmap>();
With FileTypeChecker you can easily check if the file is a general type. We create some extension methods that will give you this flexibility
using FileTypeChecker.Extensions;
bool isImage = fileStream.IsImage();
bool isArchive = fileStream.IsArchive();
Or
bool isImage = FileTypeValidator.IsImage(fileStream);
bool isArchive = FileTypeValidator.IsArchive(fileStream);