26 if (std::fseek(f.get(), -4,
SEEK_END) != 0)
27 sys_fail(
"fseek() failed (empty file?): " + path);
28 long pos = std::ftell(f.get());
30 sys_fail(
"ftell() failed on " + path);
33 if (std::fread(buf, 1, 4, f.get()) != 4)
34 sys_fail(
"Failed to read last 4 bytes of: " + path);
35 unsigned orig_size = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
39 constexpr size_t max_uint = 4294967295U;
42 fail(
"Cannot determine uncompressed size of " + path +
43 "\nWould it be " + std::to_string(
gzipped_size) +
" -> " +
78#if ZLIB_VERNUM >= 0x1235
110 if (size > 3221225471)
112 fail(
"For now gz files above 3 GiB uncompressed are not supported.\n"
113 "To read " +
path() +
" first uncompress it.");
119 }
else if (
limit == 0) {
123 if (
mem.size() > 3221225471)
124 fail(
"For now gz files above 3 GiB uncompressed are not supported.\n"
125 "To read " +
path() +
" first uncompress it.");
139#if ZLIB_VERNUM >= 0x1235
size_t gzread_checked(void *buf, size_t len)
MaybeGzipped(const std::string &path)
GzStream get_uncompressing_stream()
bool is_compressed() const
CharArray uncompress_into_buffer(size_t limit=0)
std::string basepath() const
std::unique_ptr< std::FILE, decltype(&std::fclose)> fileptr_t
size_t estimate_uncompressed_size(const std::string &path)
bool iends_with(const std::string &str, const std::string &suffix)
fileptr_t file_open(const char *path, const char *mode)
GEMMI_COLD void sys_fail(const std::string &msg)
void fail(const std::string &msg)
size_t big_gzread(gzFile file, void *buf, size_t len)
char * gets(char *line, int size)
bool read(void *buf, size_t len)