1
1

ZipDetector.cs 1.0 KB

12345678910111213141516171819202122232425
  1. using System.Reflection;
  2. using Masuit.Tools.Mime;
  3. namespace Masuit.Tools.Files.FileDetector.Detectors;
  4. [FormatCategory(FormatCategory.Compression)]
  5. [FormatCategory(FormatCategory.Archive)]
  6. internal sealed class ZipDetector : AbstractSignatureDetector
  7. {
  8. private static readonly SignatureInformation[] ZipSignatureInfo = {
  9. new () { Position = 0, Signature = new byte [] { 0x50, 0x4b, 0x03, 0x04 } },
  10. new () { Position = 0, Signature = new byte [] { 0x50, 0x4b, 0x05, 0x06 } },
  11. new () { Position = 0, Signature = new byte [] { 0x50, 0x4b, 0x07, 0x08 } },
  12. };
  13. public override string Extension => "zip";
  14. public override string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
  15. public override List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
  16. protected override SignatureInformation[] SignatureInformations => ZipSignatureInfo;
  17. public override string ToString() => "ZIP Detector";
  18. }