gzcon                  package:base                  R Documentation

(_D_e)_c_o_m_p_r_e_s_s _I/_O _T_h_r_o_u_g_h _C_o_n_n_e_c_t_i_o_n_s

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

     gzcon(con, level = 6, allowNonCompressed = TRUE)

_A_r_g_u_m_e_n_t_s:

     con: a connection.

   level: integer between 0 and 9, the compression level when writing.

allowNonCompressed: logical.  When reading, should non-compressed files
          (lacking the 'gzip' magic header) be allowed?

_D_e_t_a_i_l_s:

     If 'con' is open then the modified connection is opened.  Closing
     the wrapper connection will also close the underlying connection.

     Reading from a connection which does not supply a 'gzip' magic
     header is equivalent to reading from the original connection if
     'allowNonCompressed' is true, otherwise an error.

     The original connection is unusable: any object pointing to it
     will now refer to the modified connection.

_V_a_l_u_e:

     An object inheriting from class '"connection"'.  This is the same
     connection _number_ as supplied, but with a modified internal
     structure.

_S_e_e _A_l_s_o:

     'gzfile'

_E_x_a_m_p_l_e_s:

     ## Not run: 
     ## This example may not still be 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))
     ## End(Not run)

     ## 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")))
     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")

