Skip to content
Prev 397770 / 398500 Next

Possible bug in gzcon() (6161:src/main/connections.c)

? Fri, 25 Apr 2025 13:41:35 +0000
Andr? Wildberg <andre.wildberg at outlook.com> ?????:
I can reproduce the problem (with slightly different numbers):

length(readLines(gzcon(file("USW00014839.csv.gz", "rb"), text = TRUE)))
# [1] 28002
length(readLines("USW00014839.csv.gz"))
# [1] 429535

The underlying reason for the problem you're having with gzcon() is
most likely that the gzip archive has been concatenated from multiple
separate archives:

perl -MIO::Uncompress::Gunzip -E'
 my $z = IO::Uncompress::Gunzip::->new(shift);
 say "end of stream" while $z->nextStream() == 1;
' -- USW00014839.csv.gz
# end of stream
# end of stream
# end of stream
# end of stream
# end of stream

readLines("USW00014839.csv.gz") calls file(), which can transparently
switch to a gzfile() connection, which supports concatenated archives,
but gzcon() currently doesn't. Feature request submitted at
<https://bugs.r-project.org/show_bug.cgi?id=18887>.