Following this answer for reading a whole file, I need to determine the uncompressed file size of a gzfile. It's saved at the last 4 bytes of the gzfile, but I couldn't find how to open the file without r will wrap it with an uncompressing layer, so I have no access to the raw gz file. I haven't found a method that provides this information as well.
Asked
Active
Viewed 200 times
1 Answers
2
Provided you are sure this is a complete gzip'd file with a single stream and <2GB uncompressed:
gz_size <- function(path) {
path <- path.expand(path)
f <- file(path, open="rb", raw=TRUE)
seek(f, -4L, "end", "read")
ret <- readBin(f, "integer", 1)
close(f)
return(ret)
}

hrbrmstr
- 77,368
- 11
- 139
- 205