RarDetector.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.Archive)]
  8. [FormatCategory(FormatCategory.Compression)]
  9. internal sealed class RarDetector : AbstractSignatureDetector
  10. {
  11. private static readonly SignatureInformation[] RarSignatureInfo = {
  12. new() { Position = 0, Signature = new byte [] { 0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00 } },
  13. new() { Position = 0, Signature = new byte [] { 0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00 } },
  14. };
  15. public override string Extension => "rar";
  16. protected override SignatureInformation[] SignatureInformations => RarSignatureInfo;
  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() => "RAR Detector";
  20. }