On Thu, 8 Sep 2011, William Dunlap wrote:

Use gzcon() to make a compressed connection and any function that write to a connection will write compressed data. E.g.,

 > con <- gzcon(file("tempfile.junk", "wb"))
 > x <- as.integer(rep(c(-127, 1, 127), c(3,2,1)))
 > writeBin(x, con, size=1)
 > close(con)
 > q("no")
 bill:158% zcat tempfile.junk | od --format d1
 0000000 -127 -127 -127    1    1  127
 0000006

(In this tiny example the gzip'ed file is bigger than the equivalent one, but it is gzip'ed.)


That's a great function. Thanks for the tip. Apparently it works in both directions. That is, I would also use gzcon for readBin:

Description:

     ‘gzcon’ provides a modified connection that wraps an existing
     connection, and decompresses reads or compresses writes through
     that connection.  Standard ‘gzip’ headers are assumed.

Perfect.  Thanks again.

Mike
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to