1
check_office <- function(hdr, path) {
2

3
  # [Content_Types.xml] || length 19
4 1
  c(
5 1
    0x5b,0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x5f,0x54,
6 1
    0x79,0x70,0x65,0x73,0x5d,0x2e,0x78,0x6d,0x6c
7 1
  ) -> pat_content_types
8

9
  # _rels/.rels || length 11
10 1
  pat_rels <- c(0x5f,0x72,0x65,0x6c,0x73,0x2f,0x2e,0x72,0x65,0x6c,0x73)
11

12 1
  if ((all(pat_content_types == hdr[31:49])) || (all(pat_rels == hdr[31:41]))) {
13

14 1
    hdr <- readBin(path, "raw", n=4096)
15

16 1
    pat_word <- c(0x77,0x6f,0x72,0x64,0x2f)
17 1
    if (length(seq_in(hdr, pat_word)) > 0)
18 0
      return("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
19

20 1
    pat_ppt <- c(0x70,0x70,0x74,0x2f)
21 1
    if (length(seq_in(hdr, pat_ppt)) > 0)
22 0
      return("application/vnd.openxmlformats-officedocument.presentationml.presentation")
23

24 1
    pat_xl <- c(0x78,0x6c,0x2f)
25 1
    if (length(seq_in(hdr, pat_xl)) > 0)
26 1
      return("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
27

28
  }
29

30 1
  return(NULL)
31

32
}

Read our documentation on viewing source code .

Loading