addFilesInZip | R Documentation |
addFilesInZip()
will create new or open existing ZIP file, and
add one or more compressed files potentially using the seek optimization
extension. This function is basically a wrapper for CPLAddFileInZip()
in the GDAL Common Portability Library, but optionally creates a new ZIP
file first (with CPLCreateZip()
). It provides a subset of functionality
in the GDAL sozip
command-line utility
(https://gdal.org/en/stable/programs/sozip.html). Requires GDAL >= 3.7.
addFilesInZip(
zip_file,
add_files,
overwrite = FALSE,
full_paths = TRUE,
sozip_enabled = NULL,
sozip_chunk_size = NULL,
sozip_min_file_size = NULL,
num_threads = NULL,
content_type = NULL,
quiet = FALSE
)
zip_file |
Filename of the ZIP file. Will be created if it does not
exist or if |
add_files |
Character vector of one or more input filenames to add. |
overwrite |
Logical scalar. Overwrite the target zip file if it already exists. |
full_paths |
Logical scalar. By default, the full path will be stored
(relative to the current directory). |
sozip_enabled |
String. Whether to generate a SOZip index for the file.
One of |
sozip_chunk_size |
The chunk size for a seek-optimized file. Defaults to 32768 bytes. The value is specified in bytes, or K and M suffix can be used respectively to specify a value in kilo-bytes or mega-bytes. Will be coerced to string. |
sozip_min_file_size |
The minimum file size to decide if a file
should be seek-optimized, in |
num_threads |
Number of threads used for SOZip generation. Defaults to
|
content_type |
String Content-Type value for the file. This is stored as a key-value pair in the extra field extension 'KV' (0x564b) dedicated to storing key-value pair metadata. |
quiet |
Logical scalar. |
A Seek-Optimized ZIP file (SOZip) contains one or more compressed files organized and annotated such that a SOZip-aware reader can perform very fast random access within the .zip file (see https://github.com/sozip/sozip-spec). Large compressed files can be accessed directly from SOZip without prior decompression. The .zip file is otherwise fully backward compatible.
If sozip_enabled="AUTO"
(the default), a file is seek-optimized only if
its size is above the values of sozip_min_file_size
(default 1 MB) and
sozip_chunk_size
(default 32768
).
In "YES"
mode, all input files will be seek-optimized. In "NO"
mode, no
input files will be seek-optimized. The default can be changed with the
CPL_SOZIP_ENABLED
configuration option.
Logical indicating success (invisible TRUE
).
An error is raised if the operation fails.
The GDAL_NUM_THREADS
configuration option can be set to ALL_CPUS
or an
integer value to specify the number of threads to use for SOZip-compressed
files (see set_config_option()
).
SOZip can be validated with:
vsi_get_file_metadata(zip_file, domain="ZIP")
where zip_file
uses the /vsizip/ prefix.
vsi_get_file_metadata()
lcp_file <- system.file("extdata/storm_lake.lcp", package="gdalraster")
zip_file <- file.path(tempdir(), "storml_lcp.zip")
# Requires GDAL >= 3.7
if (as.integer(gdal_version()[2]) >= 3070000) {
addFilesInZip(zip_file, lcp_file, full_paths=FALSE, sozip_enabled="YES",
num_threads=1)
print("Files in zip archive:")
print(unzip(zip_file, list=TRUE))
# Open with GDAL using Virtual File System handler '/vsizip/'
# see: https://gdal.org/en/stable/user/virtual_file_systems.html#vsizip-zip-archives
lcp_in_zip <- file.path("/vsizip", zip_file, "storm_lake.lcp")
print("SOZip metadata:")
print(vsi_get_file_metadata(lcp_in_zip, domain="ZIP"))
ds <- new(GDALRaster, lcp_in_zip)
ds$info()
ds$close()
vsi_unlink(zip_file)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.