1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/common/gzip_file_system.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/compressed_file_system.hpp"
12
13namespace duckdb {
14
15class GZipFileSystem : public CompressedFileSystem {
16 // 32 KB
17 static constexpr const idx_t BUFFER_SIZE = 1u << 15;
18
19public:
20 unique_ptr<FileHandle> OpenCompressedFile(unique_ptr<FileHandle> handle, bool write) override;
21
22 std::string GetName() const override {
23 return "GZipFileSystem";
24 }
25
26 //! Verifies that a buffer contains a valid GZIP header
27 static void VerifyGZIPHeader(uint8_t gzip_hdr[], idx_t read_count);
28 //! Consumes a byte stream as a gzip string, returning the decompressed string
29 static string UncompressGZIPString(const string &in);
30
31 unique_ptr<StreamWrapper> CreateStream() override;
32 idx_t InBufferSize() override;
33 idx_t OutBufferSize() override;
34};
35
36static constexpr const uint8_t GZIP_COMPRESSION_DEFLATE = 0x08;
37
38static constexpr const uint8_t GZIP_FLAG_ASCII = 0x1;
39static constexpr const uint8_t GZIP_FLAG_MULTIPART = 0x2;
40static constexpr const uint8_t GZIP_FLAG_EXTRA = 0x4;
41static constexpr const uint8_t GZIP_FLAG_NAME = 0x8;
42static constexpr const uint8_t GZIP_FLAG_COMMENT = 0x10;
43static constexpr const uint8_t GZIP_FLAG_ENCRYPT = 0x20;
44
45static constexpr const uint8_t GZIP_HEADER_MINSIZE = 10;
46// MAXSIZE should be the same as input buffer size
47static constexpr const idx_t GZIP_HEADER_MAXSIZE = 1u << 15;
48static constexpr const uint8_t GZIP_FOOTER_SIZE = 8;
49
50static constexpr const unsigned char GZIP_FLAG_UNSUPPORTED =
51 GZIP_FLAG_ASCII | GZIP_FLAG_MULTIPART | GZIP_FLAG_COMMENT | GZIP_FLAG_ENCRYPT;
52
53} // namespace duckdb
54