-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileType.cs
More file actions
162 lines (132 loc) · 6.76 KB
/
Copy pathFileType.cs
File metadata and controls
162 lines (132 loc) · 6.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using SmartFileKit.Detection;
using SmartFileKit.Domain;
using System.IO;
namespace SmartFileKit
{
/// <summary>
/// Provides simple, developer-friendly static entry points to detect file categories, formats, and types.
/// </summary>
public static class FileType
{
/// <summary>
/// Detects the file format information from a stream.
/// </summary>
public static FileFormatInfo GetFormat(Stream stream) => FormatDetector.Detect(stream);
/// <summary>
/// Detects the file format information from a byte array.
/// </summary>
public static FileFormatInfo GetFormat(byte[] buffer) => FormatDetector.Detect(buffer);
/// <summary>
/// Detects the file format information from a file path.
/// </summary>
public static FileFormatInfo GetFormat(string filePath) => FormatDetector.Detect(filePath);
/// <summary>
/// Gets the high-level classification category of a stream.
/// </summary>
public static FileCategory GetCategory(Stream stream) => GetFormat(stream)?.Category ?? FileCategory.Unknown;
/// <summary>
/// Gets the high-level classification category of a byte array.
/// </summary>
public static FileCategory GetCategory(byte[] buffer) => GetFormat(buffer)?.Category ?? FileCategory.Unknown;
/// <summary>
/// Gets the high-level classification category of a file path.
/// </summary>
public static FileCategory GetCategory(string filePath) => GetFormat(filePath)?.Category ?? FileCategory.Unknown;
/// <summary>
/// Determines if the file stream is classified as an Image.
/// </summary>
public static bool IsImage(Stream stream) => GetCategory(stream) == FileCategory.Image;
/// <summary>
/// Determines if the byte array is classified as an Image.
/// </summary>
public static bool IsImage(byte[] buffer) => GetCategory(buffer) == FileCategory.Image;
/// <summary>
/// Determines if the file path is classified as an Image.
/// </summary>
public static bool IsImage(string filePath) => GetCategory(filePath) == FileCategory.Image;
/// <summary>
/// Determines if the file stream is classified as a Document.
/// </summary>
public static bool IsDocument(Stream stream) => GetCategory(stream) == FileCategory.Document;
/// <summary>
/// Determines if the byte array is classified as a Document.
/// </summary>
public static bool IsDocument(byte[] buffer) => GetCategory(buffer) == FileCategory.Document;
/// <summary>
/// Determines if the file path is classified as a Document.
/// </summary>
public static bool IsDocument(string filePath) => GetCategory(filePath) == FileCategory.Document;
/// <summary>
/// Determines if the file stream is classified as a Spreadsheet.
/// </summary>
public static bool IsSpreadsheet(Stream stream) => GetCategory(stream) == FileCategory.Spreadsheet;
/// <summary>
/// Determines if the byte array is classified as a Spreadsheet.
/// </summary>
public static bool IsSpreadsheet(byte[] buffer) => GetCategory(buffer) == FileCategory.Spreadsheet;
/// <summary>
/// Determines if the file path is classified as a Spreadsheet.
/// </summary>
public static bool IsSpreadsheet(string filePath) => GetCategory(filePath) == FileCategory.Spreadsheet;
/// <summary>
/// Determines if the file stream is classified as a Presentation.
/// </summary>
public static bool IsPresentation(Stream stream) => GetCategory(stream) == FileCategory.Presentation;
/// <summary>
/// Determines if the byte array is classified as a Presentation.
/// </summary>
public static bool IsPresentation(byte[] buffer) => GetCategory(buffer) == FileCategory.Presentation;
/// <summary>
/// Determines if the file path is classified as a Presentation.
/// </summary>
public static bool IsPresentation(string filePath) => GetCategory(filePath) == FileCategory.Presentation;
/// <summary>
/// Determines if the file stream is classified as an Archive.
/// </summary>
public static bool IsArchive(Stream stream) => GetCategory(stream) == FileCategory.Archive;
/// <summary>
/// Determines if the byte array is classified as an Archive.
/// </summary>
public static bool IsArchive(byte[] buffer) => GetCategory(buffer) == FileCategory.Archive;
/// <summary>
/// Determines if the file path is classified as an Archive.
/// </summary>
public static bool IsArchive(string filePath) => GetCategory(filePath) == FileCategory.Archive;
/// <summary>
/// Determines if the file stream is classified as Audio.
/// </summary>
public static bool IsAudio(Stream stream) => GetCategory(stream) == FileCategory.Audio;
/// <summary>
/// Determines if the byte array is classified as Audio.
/// </summary>
public static bool IsAudio(byte[] buffer) => GetCategory(buffer) == FileCategory.Audio;
/// <summary>
/// Determines if the file path is classified as Audio.
/// </summary>
public static bool IsAudio(string filePath) => GetCategory(filePath) == FileCategory.Audio;
/// <summary>
/// Determines if the file stream is classified as Video.
/// </summary>
public static bool IsVideo(Stream stream) => GetCategory(stream) == FileCategory.Video;
/// <summary>
/// Determines if the byte array is classified as Video.
/// </summary>
public static bool IsVideo(byte[] buffer) => GetCategory(buffer) == FileCategory.Video;
/// <summary>
/// Determines if the file path is classified as Video.
/// </summary>
public static bool IsVideo(string filePath) => GetCategory(filePath) == FileCategory.Video;
/// <summary>
/// Determines if the file stream is classified as an Executable/System file.
/// </summary>
public static bool IsExecutable(Stream stream) => GetCategory(stream) == FileCategory.Executable;
/// <summary>
/// Determines if the byte array is classified as an Executable/System file.
/// </summary>
public static bool IsExecutable(byte[] buffer) => GetCategory(buffer) == FileCategory.Executable;
/// <summary>
/// Determines if the file path is classified as an Executable/System file.
/// </summary>
public static bool IsExecutable(string filePath) => GetCategory(filePath) == FileCategory.Executable;
}
}