Read the Raw Binary Content of a File

Description

Read the contents of a file as bytes and create an object containing the raw data, plus optionally an interpretation of the bytes as numeric values, plus parameters controlling how to display the data.

Usage

1
2
3
4
readRaw(file, width = NULL, offset = 0, nbytes = NULL,
        machine = "hex", human = "char",
        size = switch(human, char = 1, int = 4, real = 8),
        endian = .Platform$endian, signed = TRUE)

Arguments

file

The name of a file or a connection.

width

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

offset

An offset within the file to start reading.

nbytes

The number of bytes to read from the file. NULL means read the whole file.

machine

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

human

How to print a human-readable form of the data; either "char" (an ASCII character), "int" (an integer), or "real" (a floating point number).

size

The number of bytes used to generate each value when interpreting the raw binary as character or numeric data.

endian

The endianness of the binary data; used when interpreting bytes as numeric values.

signed

Whether the bytes should be interpreted as a signed numeric value.

Details

Each individual byte is printed in the appropriate machine format, but there is only one value printed in the appropriate human format for every size bytes. Consequently, the width must be a multiple of the size.

Value

An object of class "rawBlock".

Author(s)

Paul Murrell

See Also

viewRaw readBin as.character.rawBlock print.rawBlock blockValue readFormat

Examples

1
2
3
4
5
6
7
readLines(hexViewFile("rawTest.txt"))

fileBlock <- readRaw(hexViewFile("rawTest.txt"), width=8)
blockValue(fileBlock)

fileBlock <- readRaw(hexViewFile("rawTest.int"), human="int")
blockValue(fileBlock)