Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

readFormat

Read a Binary File


Description

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

Usage

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

Examples

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)

hexView

Viewing Binary Files

v0.3-4
GPL-2
Authors
Paul Murrell [aut, cre], Chao Bian [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.