Rev 36964 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
\name{gzcon}\alias{gzcon}\title{(De)compress I/O Through Connections}\description{\code{gzcon} provides a modified connection that wraps an existingconnection, and decompresses reads or compresses writes through thatconnection. Standard \code{gzip} headers are assumed.}\usage{gzcon(con, level = 6, allowNonCompressed = TRUE)}\arguments{\item{con}{a connection.}\item{level}{integer between 0 and 9, the compression level when writing.}\item{allowNonCompressed}{logical. When reading, shouldnon-compressed input be allowed?}}\details{If \code{con} is open then the modified connection is opened. Closingthe wrapper connection will also close the underlying connection.Reading from a connection which does not supply a \code{gzip} magicheader is equivalent to reading from the original connection if\code{allowNonCompressed} is true, otherwise an error.The original connection becomes unusable: any object pointing to it willnow refer to the modified connection.When the connection is opened for reading, the input is expected tostart with the \code{gzip} magic header. If it does not and if\code{allowNonCompressed = TRUE} (the default) the input is read as-is.}\value{An object inheriting from class \code{"connection"}. This is the sameconnection \emph{number} as supplied, but with a modified internal structure.}\seealso{\code{\link{gzfile}}}\examples{\dontrun{## This example is no longer available## print the value to see what objects were created.con <- url("http://hesweb1.med.virginia.edu/biostat/s/data/sav/kprats.sav")print(load(con))close(con)}## gzfile and gzcon can inter-work.## Of course here one would used gzfile, but file() can be replaced by## any other connection generator.zz <- gzfile("ex.gz", "w")cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")close(zz)readLines(zz <- gzcon(file("ex.gz", "rb")))close(zz)unlink("ex.gz")zz <- gzcon(file("ex.gz", "wb"))cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")close(zz)readLines(zz <- gzfile("ex.gz"))close(zz)unlink("ex.gz")}\keyword{file}\keyword{connection}