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