PdfDetector.cs 773 B

12345678910111213141516171819202122
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text.RegularExpressions;
  6. using Masuit.Tools.Mime;
  7. namespace Masuit.Tools.Files.FileDetector.Detectors;
  8. [FormatCategory(FormatCategory.Document)]
  9. internal sealed class PdfDetector : AbstractRegexSignatureDetector
  10. {
  11. public override string Extension => "pdf";
  12. protected override Regex Signature => new("^%PDF-[0-9].[0-9]");
  13. public override string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
  14. public override List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
  15. public override string ToString() => "Portable Document Format Detector";
  16. }