BinaryWriter: Create a BinaryWriter Object

View source: R/binary_io.R

BinaryWriterR Documentation

Create a BinaryWriter Object

Description

This function creates a new instance of the BinaryWriter class, which supports writing of bulk binary data to a connection or file.

Usage

BinaryWriter(
  output,
  byte_offset,
  data_type,
  bytes_per_element,
  endian = .Platform$endian
)

Arguments

output

A file name (character string) to write to or a connection object.

byte_offset

An integer specifying the number of bytes to skip at the start of output.

data_type

A character string specifying the R data type of binary elements to be written.

bytes_per_element

An integer specifying the number of bytes in each data element (e.g., 4 or 8 for floating point numbers).

endian

A character string specifying the endianness of the binary output connection. Default is .Platform$endian.

Details

The BinaryWriter function creates an object for efficient writing of binary data. It can work with both file names and existing connection objects. If a file name is provided, it opens a new connection in binary write mode.

Value

A new instance of the BinaryWriter class.

See Also

BinaryWriter-class for the class definition and available methods. BinaryReader for reading binary data.

Examples

## Not run: 
# Create a BinaryWriter for a file
writer <- BinaryWriter("output.bin", byte_offset = 0, data_type = "double", 
                       bytes_per_element = 8)

# Create a BinaryWriter for an existing connection
con <- file("output.bin", "wb")
writer <- BinaryWriter(con, byte_offset = 100, data_type = "integer", 
                       bytes_per_element = 4, endian = "little")

## End(Not run)


bbuchsbaum/neuroim2 documentation built on Nov. 3, 2024, 9:31 a.m.