copystream {Rstreams}R Documentation

Copy from One Stream to Another

Description

Copies bytes from the current position of one stream to the current position of another.

Usage

  copystream(src, dest, nbytes)

Arguments

src a stream previously opened in read mode.
dest a stream previously opened in write mode.
nbytes how many bytes to copy

Details

If you request copying more bytes than are present in the source, values will not be repeated: only what is there will be copied.

Value

how many bytes were actually copied.

See Also

openstream

Examples

s <- openstream("mydata", "write")
# Write the bytes from 1 to 100 to the file
writeint(s, 1:100, 1)
closestream(s)
s1 <- openstream("mydata", "read")
s2 <- openstream("newdata", "write")
# Write a header in text, then copy the rest
writechar(s2, "Header")
copystream(s1, s2, summary(s1)$size)
closestream(s1)
closestream(s2)
unlink(c("mydata", "newdata"))