[Rd] readBin or writeBin adds extra nulls (PR#2333)

ken_yap_aus@yahoo.com ken_yap_aus@yahoo.com
Fri Nov 29 04:46:02 2002

Full_Name: Ken Yap
Version: 1.6.1
OS: Linux (SuSE 8.0)
Submission from: (NULL) (

I'm trying to copy a file using readBin and writeBin. (The reason is to be able
to pipe PostScript or PDF output to a socket later, this is just an experiment.)
I do:

zz <- file("foo.ps", "rb")
r <- readBin(zz, character(), 1000000)
yy <- file("bar.ps", "wb")
writeBin(r, yy, character(), 1000000)

When I diff the files I see differences. Every 10000 characters, the output file
an extra null byte, and the last portion is missing. Maybe the missing part is
because I forgot to flush the output of something, if someone could explain how
to do it correctly that would be nice. The extra null byte seems to be due to an
off-by-one programming error somewhere perhaps? Or am I doing something wrong?

Thanks for the great software by the way.