Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
zipfile Namespace Reference

Classes

class  ZipArchive
 
struct  ZipFileOptions
 

Enumerations

enum class  AccessPattern { ACCESS_NONE = 0 , ACCESS_NORMAL = 1 , ACCESS_RANDOM = 2 , ACCESS_SEQUENTIAL = 3 }
 

Functions

std::shared_ptr< ZipArchiveOpenZipArchive (absl::string_view path, const ZipFileOptions &options)
 
std::shared_ptr< ZipArchiveOpenZipArchive (absl::string_view path)
 

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. The zip file is treated a single-level read-only directory. The subfiles that when unzipped would be directories appear to File as zero-length files. This implementation supports only uncompressed and deflate-compressed content (compression method == 8).

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Interface for mapping the contents of a zipfile. You open a zip file archive by using the OpenZipArchive() method, which returns a shared_ptr to a ZipArchive object that maps its contents into the "/zip/" namespace. During the duration of the existence of the ZipArchive object, paths under it are available for File operations.

Only a single ZipArchive will be opened for any unique path; all of the returned shared_ptrs will point to the same underlying ZipArchive object. The contents of the ZipArchive will remain mapped into the /zip/ namespace until the last shared_ptr is destroyed and its underlying object is released.

To map the contents of zip file "/foo/bar.zip", use the following: { std::shared_ptr<zipfile::ZipArchive> zip_archive( zipfile::OpenZipArchive("/foo/bar.zip")); if (zip_archive == nullptr) { ///< Handle error }

///< Do interesting things with paths under "/zip/foo/bar.zip/..." }

Paths in the zip file are available until the last shared_ptr to the ZipArchive object is released.

You can use this pattern to read files from a Zip archive: { std::shared_ptr<zipfile::ZipArchive> zip_archive( zipfile::OpenZipArchive(filename)); if (zip_archive == nullptr) { ///< Do not continue execution of the example code. } vector<string> files; absl::Status status = file::Match(file::JoinPath("/zip", filename, "*"), &files, file::Defaults()); if (!status.ok()) { ///< Do not continue execution. } for (const string& fn : files) { File* f; absl::Status status = file::Open(fn, "r", &f, file::Defaults()); if (!status.ok()) { ///< Handle error: abort, return, or continue. } DoStuffWithFile(f); status = f->Close(); if (!status.ok()) { ///< Handle error: abort, return, or continue. } } }

Enumeration Type Documentation

◆ AccessPattern

enum class zipfile::AccessPattern
strong

Performance hint: Specify what order you expect to visit the data in the file.

Enumerator
ACCESS_NONE 

Keep whatever is default for your system (typically same as NORMAL).

ACCESS_NORMAL 

Moderate prefetching as the file gets accessed.

ACCESS_RANDOM 

No prefetching to be done, use this for random access.

ACCESS_SEQUENTIAL 

Aggressive prefetching on reads.

Definition at line 80 of file zipfile.h.

Function Documentation

◆ OpenZipArchive() [1/2]

std::shared_ptr< ZipArchive > zipfile::OpenZipArchive ( absl::string_view path)
inline

Definition at line 138 of file zipfile.h.

◆ OpenZipArchive() [2/2]

std::shared_ptr< ZipArchive > zipfile::OpenZipArchive ( absl::string_view path,
const ZipFileOptions & options )

Open and return a ZipArchive. This maps the files in PATH into the /zip/ namespace, and they will exist there until the ZipArchive is destroyed. If the archive is already opened, or opening it fails for some reason, nullptr will be returned.

The path given to OpenZipArchive must be absolute. The ZipArchive can only be used for reading zipfile contents. To modify zip file contents, use ZipFileWriter from file/zipfile/zipfilewriter.h.

The value of the returned shared_ptr may be nullptr if there is an error opening the archive. This may be caused by corruption, errors finding or opening the file, or any other problem which prevents the archive from being read.

Note
Writing to an open ZipArchive will fail in strange and mysterious ways. You have been warned. The input options argument provides controls over zip bombs as well as access pattern controls

unimplemented

Definition at line 32 of file zipfile.cc.