WebPDetector.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.Image)]
  8. [FormatCategory(FormatCategory.Video)]
  9. internal class WebPDetector : AbstractSignatureDetector
  10. {
  11. private static readonly SignatureInformation[] WebpSignatureInfo = {
  12. new() { Position = 0, Signature = new byte [] { 0x52, 0x49, 0x46, 0x46 } },
  13. new() { Position = 8, Signature = new byte [] { 0x57, 0x45, 0x42, 0x50 }, Presignature = new byte [] { 0x52, 0x49, 0x46, 0x46 } },
  14. };
  15. public override string Extension => "webp";
  16. public override string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
  17. public override List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
  18. protected override SignatureInformation[] SignatureInformations => WebpSignatureInfo;
  19. public override string ToString() => "WebP Detector";
  20. }