Learn R Programming

hexView (version 0.3-4)

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.

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.

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

See Also

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

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab