OR-Tools  9.6
gzipfile.h
Go to the documentation of this file.
1 // Copyright 2010-2022 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_BASE_GZIPFILE_H_
15 #define OR_TOOLS_BASE_GZIPFILE_H_
16 
17 #include "absl/strings/string_view.h"
18 #include "ortools/base/basictypes.h" // for Ownership enum
19 #include "zlib.h" // for Z_DEFAULT_COMPRESSION
20 
21 class File;
22 
23 // Argument type used in interfaces that can optionally accept appended
24 // compressed streams. If kConcatenateStreams is passed, the output will
25 // include all streams. Otherwise only the first stream is output.
26 enum class AppendedStreams {
29 };
30 
31 // Argument type used in interfaces that can optionally take ownership
32 // of a passed in argument. If TAKE_OWNERSHIP is passed, the called
33 // object takes ownership of the argument. Otherwise it does not.
35 
36 // Return a readonly file that contains a uncompressed version of
37 // another File.
38 //
39 // If "ownership == TAKE_OWNERSHIP", the file takes ownership of
40 // "compressed_file". "compressed_file" will be deleted when the file is
41 // closed.
42 //
43 // If "ownership == "DO_NOT_TAKE_OWNERSHIP", the file does not take
44 // ownership of "compressed_file". The client must guarantee that
45 // "compressed_file" remains live while the file is being accessed and
46 // that operations on "compressed_file" do not interfere (e.g., move
47 // the read pointer) with the file.
48 //
49 // If "appended_streams" == "kConcatenateStreams" decompression will process
50 // and output each compressed stream present in the input.
51 //
52 // If "appended_streams" == "kIgnoreAppendedData" decompression will stop
53 // after the first stream.
54 //
55 // The compressed file may be either a gzip format file, a zlib compressed
56 // file, or a unix compress format file. The only difference between gzip
57 // and zlib is whether the file has a gzip header and trailer. If the file
58 // consists of multiple gzip files concatenated together, then we will
59 // decompress them into a single concatenated output. This may seem weird
60 // but that's what the gzip commandline tool does. If we didn't do this
61 // we would silently truncate some input files upon decompression.
62 // Otherwise we signal an error for any invalid data after the compressed
63 // stream.
64 File* GZipFileReader(absl::string_view name, File* compressed_file,
65  Ownership ownership, AppendedStreams appended_streams);
66 // appended_streams defaults to kConcatenateStreams if not specified.
67 inline File* GZipFileReader(absl::string_view name, File* compressed_file,
68  Ownership ownership) {
69  return GZipFileReader(name, compressed_file, ownership,
71 }
72 
73 #endif // OR_TOOLS_BASE_GZIPFILE_H_
Definition: base/file.h:33
const std::string name
AppendedStreams
Definition: gzipfile.h:26
File * GZipFileReader(absl::string_view name, File *compressed_file, Ownership ownership, AppendedStreams appended_streams)
Definition: gzipfile.cc:25
Ownership
Definition: gzipfile.h:34
@ TAKE_OWNERSHIP
Definition: gzipfile.h:34
@ DO_NOT_TAKE_OWNERSHIP
Definition: gzipfile.h:34