readFormat: Read a Binary File

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/viewFormat.R

Description

Read the raw binary content of a file using a description of the binary format.

Usage

1
2
readFormat(file, format, width = NULL, offset = 0, machine = "hex",
           flatten = TRUE)

Arguments

file

The name of a file or a connection.

format

A "memFormat" object.

width

The number of bytes to print per row when displaying the file.

offset

An offset within the file to start reading.

machine

How to print each byte when displaying the file; either "hex" or "binary".

flatten

If TRUE the list of blocks created from the "memFormat" description are flattened to a list of depth 1.

Details

This function uses a "memFormat" description to read the raw binary content of a file and interpret sub-blocks of the file as distinct (blocks of) values.

The "memFormat" can described a nested structure of blocks. The flatten argument is used to convert nested format structures to a flat (depth of one) structure.

The format is always flattened for display, but extracting

Value

A "rawFormat" object, which is a list:

blocks

A list (of lists) of "rawBlock" objects.

offset

The offset in the file where reading began.

nbytes

The number of bytes read from the file.

Author(s)

Paul Murrell

See Also

viewFormat memFormat as.character.rawFormat print.rawFormat readRaw readBin

Examples

1
2
3
4
5
6
7
fileFormat <- readFormat(hexViewFile("rawTest.int"),
                         memFormat(int1=integer4, int2=integer4))
blockValue(fileFormat$blocks$int2)

fileFormat <- readFormat(hexViewFile("rawTest.int"),
                         memFormat(integers=vectorBlock(integer4, 20)))
blockValue(fileFormat$blocks$integers)

Example output

[1] 2
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20

hexView documentation built on May 2, 2019, 7:02 a.m.