reader.cpp 1007 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <../base.hpp>
  2. #define READER_CPP
  3. #include "reader.hpp"
  4. #include "filereader.cpp"
  5. #if defined(GZIP_SUPPORT)
  6. #include "gzreader.cpp"
  7. #include "zipreader.cpp"
  8. #endif
  9. #if defined(JMA_SUPPORT)
  10. #include "jmareader.cpp"
  11. #endif
  12. Reader::Type Reader::detect(const char *fn, bool inspectheader) {
  13. file fp;
  14. if(!fp.open(fn, file::mode_read)) return Unknown;
  15. uint8_t p[8];
  16. memset(p, 0, sizeof p);
  17. fp.read(p, 8);
  18. fp.close();
  19. if(inspectheader == true) {
  20. //inspect file header to determine type
  21. if(p[0] == 0x1f && p[1] == 0x8b && p[2] == 0x08 && p[3] <= 0x1f) return GZIP;
  22. if(p[0] == 0x50 && p[1] == 0x4b && p[2] == 0x03 && p[3] == 0x04) return ZIP;
  23. if(p[0] == 0x4a && p[1] == 0x4d && p[2] == 0x41 && p[3] == 0x00 && p[4] == 0x4e) return JMA;
  24. } else {
  25. //check file extension to determine type
  26. if(striend(fn, ".gz")) return GZIP;
  27. if(striend(fn, ".zip") || striend(fn, ".z")) return ZIP;
  28. if(striend(fn, ".jma")) return JMA;
  29. }
  30. return Normal;
  31. }