@@ -147,31 +147,85 @@ public static void RegisterFileDetector(IFileDetector fileDetector)
147147 }
148148 }
149149
150+ /// <summary>
151+ /// Get every file extensions that corresponds to the file MIME type
152+ /// </summary>
153+ /// <param name="fileBytes">Byte array of the file</param>
154+ /// <returns>
155+ /// An array of file extensions without leading dot or null if the file is not recognized
156+ /// </returns>
157+ /// <exception cref="ArgumentNullException">
158+ /// If the <paramref name="fileBytes"/> is null
159+ /// </exception>
160+ public static string [ ] GetFileExtensions ( byte [ ] fileBytes )
161+ {
162+ if ( fileBytes == null )
163+ {
164+ throw new ArgumentNullException ( nameof ( fileBytes ) ) ;
165+ }
166+
167+ using ( var stream = new MemoryStream ( fileBytes ) )
168+ {
169+ return GetFileExtensions ( stream ) ;
170+ }
171+ }
172+
150173 /// <summary>
151174 /// Get every file extensions that corresponds to the file MIME type
152175 /// </summary>
153176 /// <param name="stream">Source stream of the file</param>
154177 /// <returns>
155- /// The file extensions without leading dot or null if the file is not recognized
178+ /// An array of file extensions without leading dot or null if the file is not recognized
156179 /// </returns>
157- /// <exception cref="ArgumentNullException"/>
158- /// <exception cref="ArgumentException"/>
180+ /// <exception cref="ArgumentNullException">
181+ /// If the <paramref name="stream"/> is null
182+ /// </exception>
183+ /// <exception cref="ArgumentException">
184+ /// If the <paramref name="stream"/> is not seekable and/or readable
185+ /// </exception>
159186 public static string [ ] GetFileExtensions ( Stream stream )
160187 {
161188 var mime = GetMimeType ( stream ) ;
162189
163190 return mime != null ? MimeTypes . GetMimeTypeExtensions ( mime ) . ToArray ( ) : null ;
164191 }
165192
193+ /// <summary>
194+ /// Get the MIME type of a file
195+ /// </summary>
196+ /// <param name="fileBytes">Byte array of the file</param>
197+ /// <returns>
198+ /// The MIME type or null if the file is not recognized
199+ /// </returns>
200+ /// <exception cref="ArgumentNullException">
201+ /// If the <paramref name="fileBytes"/> is null
202+ /// </exception>
203+ public static string GetMimeType ( byte [ ] fileBytes )
204+ {
205+ if ( fileBytes == null )
206+ {
207+ throw new ArgumentNullException ( nameof ( fileBytes ) ) ;
208+ }
209+
210+ using ( var stream = new MemoryStream ( fileBytes ) )
211+ {
212+ return GetMimeType ( stream ) ;
213+ }
214+ }
215+
166216 /// <summary>
167217 /// Get the MIME type of a file
168218 /// </summary>
169219 /// <param name="stream">Source stream of the file</param>
170220 /// <returns>
171221 /// The MIME type or null if the file is not recognized
172222 /// </returns>
173- /// <exception cref="ArgumentNullException"/>
174- /// <exception cref="ArgumentException"/>
223+ /// <exception cref="ArgumentNullException">
224+ /// If the <paramref name="stream"/> is null
225+ /// </exception>
226+ /// <exception cref="ArgumentException">
227+ /// If the <paramref name="stream"/> is not seekable and/or readable
228+ /// </exception>
175229 public static string GetMimeType ( Stream stream )
176230 {
177231 if ( stream == null )
0 commit comments