Stream read functions        package:Rstreams        R Documentation

_R_e_a_d _B_i_n_a_r_y _D_a_t_a _f_r_o_m _a _S_t_r_e_a_m

_D_e_s_c_r_i_p_t_i_o_n:

     Reads binary data from the current position within a stream.

_U_s_a_g_e:

     readint(stream, n = 1, size = 4, signed = TRUE, swapbytes = FALSE)
     readfloat(stream, n = 1, size = 8, swapbytes = FALSE)
     readcomplex(stream, n = 1, size = 8, swapbytes = FALSE)
     readchar(stream, n = 1, len = NA, bufsize = 256)
     readlines(stream, n = 1, bufsize = 256,
               eol = getstreameol(stream, bufsize))

_A_r_g_u_m_e_n_t_s:

  stream: a previously opened stream.

       n: the number of items to read.

    size: the size of each item, in bytes.

  signed: whether to interpret integer data as signed or unsigned.

swapbytes: whether to change little- to big-endian or vice versa.

     len: the number of characters to read into each string.

 bufsize: the initial buffer size to be used when reading variable
          length strings.  This will be grown as needed.

     eol: the end of line marker

_D_e_t_a_i_l_s:

     Signed integers of sizes 1, 2, 4, and 8 bytes can be read. 
     Unsigned integers of any size up to 8 bytes can be read. (Integers
     larger than are supported in R will be returned in a vector of
     doubles.)

     Floats of sizes `float', `double' and `long double' can be read
     (where `long double' might be 10, 12 or 16 bytes or even the same
     type as `double').  Complex values using any of the float sizes
     for the real and complex parts can be read.  Any size of character
     string that you can create can be read.

     If `swapbytes = TRUE', then when reading any multi-byte numbers,
     the byte order within the number will be swapped.  This allows you
     to read data that was written on a machine that uses a different
     convention for numeric storage, i.e. read little-endian data from
     a big-endian machine, or vice versa.

     `readchar' can either read strings of fixed size given by `len',
     or if `len = NA', ASCII-zero-delimited strings.

     `readlines' can read variable length strings with arbitrary end of
     line markers.  See `getstreameol' for the default choice of end of
     line marker.

_V_a_l_u_e:

     A vector of integers, doubles, complex values or character
     strings. This may be shorter than requested if there was
     insufficient data on the file.

_S_e_e _A_l_s_o:

     `openstream', `writeint', `getstreameol'

_E_x_a_m_p_l_e_s:

     ## find out endian-ness
     if(R.version$major == 1 && R.version$minor >= 2.0) .Platform$endian

     s <- openstream("mydata", "write")
     writeint(s, 1:10, 1)
     writeint(s, 21:30, 2)
     writeint(s, 41:50, 4)
     writefloat(s, 401:410, 4)
     writefloat(s, 801:810, 8)
     writechar(s, c("a string", "or two"), asciiz = TRUE)
     closestream(s)

     s <- openstream("mydata", "read")
     readint(s, 10, 1)
     readint(s, 10, 2)
     readint(s, 10, 4)
     readfloat(s, 10, 4)
     readfloat(s, 10, 8)
     readchar(s, 2)
     closestream(s)

     dump("openstream", "mydata")
     s <- openstream("mydata")
     readlines(s, 2)
     closestream(s)

     unlink("mydata")

