ZipDetector.cs 1.1 KB

12345678910111213141516171819202122232425262728
  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.Compression)]
  8. [FormatCategory(FormatCategory.Archive)]
  9. internal class ZipDetector : AbstractSignatureDetector
  10. {
  11. private static readonly SignatureInformation[] ZipSignatureInfo = {
  12. new () { Position = 0, Signature = new byte [] { 0x50, 0x4b, 0x03, 0x04 } },
  13. new () { Position = 0, Signature = new byte [] { 0x50, 0x4b, 0x05, 0x06 } },
  14. new () { Position = 0, Signature = new byte [] { 0x50, 0x4b, 0x07, 0x08 } },
  15. };
  16. public override string Extension => "zip";
  17. public override string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
  18. public override List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
  19. protected override SignatureInformation[] SignatureInformations => ZipSignatureInfo;
  20. public override string ToString() => "ZIP Detector";
  21. }