EVOLUTION-MANAGER
Edit File: gzcon.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: (De)compress I/O Through Connections</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for gzcon {base}"><tr><td>gzcon {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> (De)compress I/O Through Connections </h2> <h3>Description</h3> <p><code>gzcon</code> provides a modified connection that wraps an existing connection, and decompresses reads or compresses writes through that connection. Standard <code>gzip</code> headers are assumed. </p> <h3>Usage</h3> <pre> gzcon(con, level = 6, allowNonCompressed = TRUE, text = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>con</code></td> <td> <p>a connection.</p> </td></tr> <tr valign="top"><td><code>level</code></td> <td> <p>integer between 0 and 9, the compression level when writing.</p> </td></tr> <tr valign="top"><td><code>allowNonCompressed</code></td> <td> <p>logical. When reading, should non-compressed input be allowed?</p> </td></tr> <tr valign="top"><td><code>text</code></td> <td> <p>logical. Should the connection be text-oriented? This is distinct from the mode of the connection (must always be binary). If <code>TRUE</code>, <code><a href="pushBack.html">pushBack</a></code> works on the connection, otherwise <code><a href="readBin.html">readBin</a></code> and friends apply.</p> </td></tr> </table> <h3>Details</h3> <p>If <code>con</code> is open then the modified connection is opened. Closing the wrapper connection will also close the underlying connection. </p> <p>Reading from a connection which does not supply a <code>gzip</code> magic header is equivalent to reading from the original connection if <code>allowNonCompressed</code> is true, otherwise an error. </p> <p>Compressed output will contain embedded NUL bytes, and so <code>con</code> is not permitted to be a <code><a href="textconnections.html">textConnection</a></code> opened with <code>open = "w"</code>. Use a writable <code><a href="rawConnection.html">rawConnection</a></code> to compress data into a variable. </p> <p>The original connection becomes unusable: any object pointing to it will now refer to the modified connection. For this reason, the new connection needs to be closed explicitly. </p> <h3>Value</h3> <p>An object inheriting from class <code>"connection"</code>. This is the same connection <em>number</em> as supplied, but with a modified internal structure. It has binary mode. </p> <h3>See Also</h3> <p><code><a href="connections.html">gzfile</a></code></p> <h3>Examples</h3> <pre> ## Uncompress a data file from a URL z <- gzcon(url("http://www.stats.ox.ac.uk/pub/datasets/csb/ch12.dat.gz")) # read.table can only read from a text-mode connection. raw <- textConnection(readLines(z)) close(z) dat <- read.table(raw) close(raw) dat[1:4, ] ## gzfile and gzcon can inter-work. ## Of course here one would use gzfile, but file() can be replaced by ## any other connection generator. zzfil <- tempfile(fileext = ".gz") zz <- gzfile(zzfil, "w") cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n") close(zz) readLines(zz <- gzcon(file(zzfil, "rb"))) close(zz) unlink(zzfil) zzfil2 <- tempfile(fileext = ".gz") zz <- gzcon(file(zzfil2, "wb")) cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n") close(zz) readLines(zz <- gzfile(zzfil2)) close(zz) unlink(zzfil2) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>