Gemmi C++ API
Loading...
Searching...
No Matches
gz.hpp
Go to the documentation of this file.
1// Copyright 2017 Global Phasing Ltd.
2//
3// Functions for transparent reading of gzipped files. Uses zlib.
4
5#ifndef GEMMI_GZ_HPP_
6#define GEMMI_GZ_HPP_
7#include <string>
8#include "fail.hpp" // GEMMI_DLL
9#include "input.hpp" // BasicInput
10#include "util.hpp" // iends_with
11
12namespace gemmi {
13
14GEMMI_DLL extern const char* const zlib_description;
15
16GEMMI_DLL size_t estimate_uncompressed_size(const std::string& path);
17
18// the same interface as FileStream and MemoryStream
20 GzStream(void* f_) : f(f_) {}
21 char* gets(char* line, int size) override;
22 int getc() override;
23 bool read(void* buf, size_t len) override;
24 bool skip(size_t n) override;
25 long tell() override;
26 std::string read_rest() override;
27
28private:
29 void* f; // implementation detail
30};
31
33public:
34 explicit MaybeGzipped(const std::string& path);
36 size_t gzread_checked(void* buf, size_t len);
37 bool is_compressed() const { return iends_with(path(), ".gz"); }
38 std::string basepath() const {
39 return is_compressed() ? path().substr(0, path().size() - 3) : path();
40 }
41
43
44 std::unique_ptr<AnyStream> create_stream();
45
46private:
47 void* file_ = nullptr;
48};
49
50} // namespace gemmi
51
52#endif
size_t gzread_checked(void *buf, size_t len)
MaybeGzipped(const std::string &path)
std::unique_ptr< AnyStream > create_stream()
bool is_compressed() const
Definition gz.hpp:37
CharArray uncompress_into_buffer(size_t limit=0)
std::string basepath() const
Definition gz.hpp:38
fail(), unreachable() and __declspec/__attribute__ macros
#define GEMMI_DLL
Definition fail.hpp:53
Input abstraction. Used to decouple file reading and decompression.
GEMMI_DLL const char *const zlib_description
GEMMI_DLL size_t estimate_uncompressed_size(const std::string &path)
bool iends_with(const std::string &str, const std::string &suffix)
Definition util.hpp:99
bool skip(size_t n) override
int getc() override
bool read(void *buf, size_t len) override
long tell() override
GzStream(void *f_)
Definition gz.hpp:20
char * gets(char *line, int size) override
std::string read_rest() override
Utilities. Mostly for working with strings and vectors.