GifDetector.cs 1.0 KB

123456789101112131415161718192021222324252627
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Reflection;
  5. using Masuit.Tools.Mime;
  6. namespace Masuit.Tools.Files.FileDetector.Detectors;
  7. [FormatCategory(FormatCategory.Video)]
  8. [FormatCategory(FormatCategory.Image)]
  9. internal class GifDetector : AbstractSignatureDetector
  10. {
  11. private static readonly SignatureInformation[] GifSignatureInfo = {
  12. new() { Position = 0, Signature = new byte [] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 } },
  13. new() { Position = 0, Signature = new byte [] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 } },
  14. };
  15. public override string Extension => "gif";
  16. protected override SignatureInformation[] SignatureInformations => GifSignatureInfo;
  17. public override string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
  18. public override List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
  19. public override string ToString() => "Graphics Interchange Format Detector";
  20. }