r 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #------------------------------------------------------------------------------
  2. # $File: r,v 1.1 2025/02/10 17:48:42 christos Exp $
  3. # file(1) magic for R's RDS and RData file formats
  4. # Copyright (C) 2025 Gert Hulselmans <hulselmansgert@gmail.com>
  5. #
  6. # URLS:
  7. # https://cran.r-project.org/doc/manuals/r-release/R-ints.html#Serialization-Formats
  8. # https://rdata.readthedocs.io/en/latest/_modules/rdata/parser/_parser.html
  9. #
  10. # Example files:
  11. # https://github.com/vnmabus/rdata/tree/develop/rdata/tests/data
  12. #
  13. ###############################################################################
  14. ###############################################################################
  15. # RDS format
  16. ###############################################################################
  17. 0 name RDS
  18. # Check for RDS ASCII formats.
  19. >0 string A\n2\n R RDS (ASCII format v2)
  20. >0 string A\n3\n R RDS (ASCII format v3)
  21. >0 string A\r\n2\r\n R RDS (ASCII CRLF format v2)
  22. >0 string A\r\n3\r\n R RDS (ASCII CRLF format v3)
  23. # Check for RDS binary formats with native word order.
  24. >0 string B\n\0\0\0 R RDS (Native (big-endian) word order format
  25. >>0 use RDS_binary_version_info
  26. >0 string B\n\2\0\0 R RDS (Native (little-endian) word order format
  27. >>0 use ^RDS_binary_version_info
  28. >0 string B\n\3\0\0 R RDS (Native (little-endian) word order format
  29. >>0 use ^RDS_binary_version_info
  30. # Check for RDS XDR binary save format.
  31. >0 string X\n\0\0\0 R RDS (XDR binary save format
  32. >>0 use RDS_binary_version_info
  33. # Parse version numbers from RDS if it was one of the binary versions.
  34. 0 name RDS_binary_version_info
  35. >2 belong >-1 v%d)
  36. >6 beshort >-1 \b, written by R v%d.
  37. >8 byte >-1 \b%d.
  38. >9 byte >-1 \b%d
  39. >10 beshort >-1 \b, readable from R v%d.
  40. >12 byte >-1 \b%d.
  41. >13 byte >-1 \b%d
  42. >2 belong >2
  43. >>14 pstring/L x \b, %s encoded
  44. # Check if file is one of the RDS ASCII formats.
  45. 0 string A
  46. >0 use RDS not_printed
  47. !:ext rds
  48. # Check if file is RDS binary native format.
  49. 0 string B
  50. >0 use RDS not_printed
  51. !:ext rds
  52. # Check if file is RDS XDR binary save format.
  53. 0 string X
  54. >0 use RDS not_printed
  55. !:ext rds
  56. ###############################################################################
  57. # RData file formats: magic bytes followed by RDS container.
  58. ###############################################################################
  59. 0 string RDA2\n R RData version 2 (ASCII),
  60. !:ext rda/rdata
  61. >5 use RDS
  62. 0 string RDA3\n R RData version 3 (ASCII),
  63. !:ext rda/rdata
  64. >5 use RDS
  65. 0 string RDX2\n R RData version 2 (binary),
  66. !:ext rda/rdata
  67. >5 use RDS
  68. 0 string RDX3\n R RData version 3 (binary),
  69. !:ext rda/rdata
  70. >5 use RDS