Skip to contents

Create an iterator to read binary data from a connection.

Usage

ireadBin(
  con,
  what = "raw",
  n = 1L,
  size = NA_integer_,
  signed = TRUE,
  endian = .Platform$endian,
  ipos = NULL
)

Arguments

con

A connection object or a character string naming a file or a raw vector.

what

Either an object whose mode will give the mode of the vector to be read, or a character vector of length one describing the mode: one of “numeric”, “double”, “integer”, “int”, “logical”, “complex”, “character”, “raw”. Unlike readBin, the default value is “raw”.

n

integer. The (maximal) number of records to be read each time the iterator is called.

size

integer. The number of bytes per element in the byte stream. The default, ‘NA_integer_’, uses the natural size.

signed

logical. Only used for integers of sizes 1 and 2, when it determines if the quantity on file should be regarded as a signed or unsigned integer.

endian

The endian-ness ('“big”' or '“little”') of the target system for the file. Using '“swap”' will force swapping endian-ness.

ipos

iterable. If not NULL, values from this iterable will be used to do a seek on the file before calling readBin.

Value

An iteror reading binary chunks from the connection.

Details

Originally from the itertools package.

Examples


zz <- file("testbin", "wb")
writeBin(1:100, zz)
close(zz)

it <- ihasNext(ireadBin("testbin", integer(), 10))
repeat print(nextOr(it, break))
#>  [1]  1  2  3  4  5  6  7  8  9 10
#>  [1] 11 12 13 14 15 16 17 18 19 20
#>  [1] 21 22 23 24 25 26 27 28 29 30
#>  [1] 31 32 33 34 35 36 37 38 39 40
#>  [1] 41 42 43 44 45 46 47 48 49 50
#>  [1] 51 52 53 54 55 56 57 58 59 60
#>  [1] 61 62 63 64 65 66 67 68 69 70
#>  [1] 71 72 73 74 75 76 77 78 79 80
#>  [1] 81 82 83 84 85 86 87 88 89 90
#>  [1]  91  92  93  94  95  96  97  98  99 100
unlink("testbin")