Skip to content

Commit

Permalink
add text argument to gzcon(); makes connection text-oriented (not tex…
Browse files Browse the repository at this point in the history
…t mode)

git-svn-id: https://svn.r-project.org/R/trunk@70399 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
lawrence committed Mar 30, 2016
1 parent 2a2f940 commit cd3598f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions doc/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@
directly aim for less than \code{min(n,p)} PC's. The
\code{summary()} and its \code{print()} method have been amended,
notably for this case.

\item \code{gzcon} gains a new option \code{text}, which marks the
connection as text-oriented (so e.g. \code{pushBack} works). It is
still always opened in binary mode.
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/library/base/R/connections.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ writeChar <- function(object, con, nchars = nchar(object, type="chars"),
.Internal(writeChar(object, con, as.integer(nchars), eos, useBytes))
}

gzcon <- function(con, level = 6, allowNonCompressed = TRUE)
.Internal(gzcon(con, level, allowNonCompressed))
gzcon <- function(con, level = 6, allowNonCompressed = TRUE, text = FALSE)
.Internal(gzcon(con, level, allowNonCompressed, text))

socketSelect <- function(socklist, write = FALSE, timeout = NULL) {
if (is.null(timeout))
Expand Down
6 changes: 5 additions & 1 deletion src/library/base/man/gzcon.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
connection. Standard \code{gzip} headers are assumed.
}
\usage{
gzcon(con, level = 6, allowNonCompressed = TRUE)
gzcon(con, level = 6, allowNonCompressed = TRUE, text = FALSE)
}
\arguments{
\item{con}{a connection.}
\item{level}{integer between 0 and 9, the compression level when writing.}
\item{allowNonCompressed}{logical. When reading, should
non-compressed input be allowed?}
\item{text}{logical. Should the connection be text-oriented? This is
distinct from the mode of the connection (must always be binary).
If \code{TRUE}, \code{\link{pushBack}} works on the connection,
otherwise \code{\link{readBin}} and friends apply.}
}
\details{
If \code{con} is open then the modified connection is opened. Closing
Expand Down
8 changes: 6 additions & 2 deletions src/main/connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -5482,6 +5482,7 @@ SEXP attribute_hidden do_gzcon(SEXP call, SEXP op, SEXP args, SEXP rho)
int icon, level, allow;
Rconnection incon = NULL, new = NULL;
char *m, *mode = NULL /* -Wall */, description[1000];
Rboolean text;

checkArity(op, args);
if(!inherits(CAR(args), "connection"))
Expand All @@ -5493,7 +5494,10 @@ SEXP attribute_hidden do_gzcon(SEXP call, SEXP op, SEXP args, SEXP rho)
allow = asLogical(CADDR(args));
if(allow == NA_INTEGER)
error(_("'allowNonCompression' must be TRUE or FALSE"));

text = asLogical(CADDDR(args));
if(text == NA_INTEGER)
error(_("'text' must be TRUE or FALSE"));

if(incon->isGzcon) {
warning(_("this is already a 'gzcon' connection"));
return CAR(args);
Expand Down Expand Up @@ -5524,7 +5528,7 @@ SEXP attribute_hidden do_gzcon(SEXP call, SEXP op, SEXP args, SEXP rho)
error(_("allocation of 'gzcon' connection failed"));
}
init_con(new, description, CE_NATIVE, mode);
new->text = FALSE;
new->text = text;
new->isGzcon = TRUE;
new->open = &gzcon_open;
new->close = &gzcon_close;
Expand Down
2 changes: 1 addition & 1 deletion src/main/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ FUNTAB R_FunTab[] =
{"getConnection",do_getconnection,0, 11, 1, {PP_FUNCALL, PREC_FN, 0}},
{"getAllConnections",do_getallconnections,0,11, 0, {PP_FUNCALL, PREC_FN, 0}},
{"summary.connection",do_sumconnection,0,11, 1, {PP_FUNCALL, PREC_FN, 0}},
{"gzcon", do_gzcon, 0, 11, 3, {PP_FUNCALL, PREC_FN, 0}},
{"gzcon", do_gzcon, 0, 11, 4, {PP_FUNCALL, PREC_FN, 0}},
{"memCompress",do_memCompress, 0, 11, 2, {PP_FUNCALL, PREC_FN, 0}},
{"memDecompress",do_memDecompress,0, 11, 2, {PP_FUNCALL, PREC_FN, 0}},

Expand Down

0 comments on commit cd3598f

Please sign in to comment.