31 const std::filesystem::path&
path
34 if (!streambuf->file_) {
35 return Err(
Error::io(std::format(
"Failed to open gzip file: {}",
path.string())));
49 return traits_type::to_int_type(*
gptr());
54 return traits_type::eof();
58 return traits_type::to_int_type(*
gptr());
62 static constexpr std::size_t kBufferSize = 8192;
66 setg(buffer_, buffer_, buffer_);
70 char buffer_[kBufferSize];
82 const std::filesystem::path&
path
86 return Err(streambuf.error());
88 return std::unique_ptr<GzIstream>(
new GzIstream(std::move(*streambuf)));
92 explicit GzIstream(std::unique_ptr<GzStreambuf> streambuf)
93 : std::istream(
nullptr), sb_(std::
move(streambuf)) {
97 std::unique_ptr<GzStreambuf> sb_;
102 FILE*
f = std::fopen(
path.string().c_str(),
"rb");
107 size_t n = std::fread(
magic, 1, 2,
f);
109 return n == 2 &&
magic[0] == 0x1F &&
magic[1] == 0x8B;
std::istream adapter for GzStreambuf.
static Result< std::unique_ptr< GzIstream > > open(const std::filesystem::path &path)
Opens a gzip file as an input stream.
std::streambuf over a gzip file (zlib gzread).
GzStreambuf(GzStreambuf &&)=delete
int_type underflow() override
static Result< std::unique_ptr< GzStreambuf > > open(const std::filesystem::path &path)
Opens path for binary gzip read.
GzStreambuf & operator=(GzStreambuf &&)=delete
GzStreambuf(const GzStreambuf &)=delete
GzStreambuf & operator=(const GzStreambuf &)=delete
bool isGzipFile(const std::filesystem::path &path)
True when path begins with the gzip magic bytes (0x1F, 0x8B).
consteval bool separatorPositionAlwaysEncodesInvalid(char *input, uint64_t separatorPosition, uint64_t index)
Recursively tests whether placing the separator byte at any position in an input of valid bytes alway...
cuda::std::unexpected< Error > Err(Error error)
Failure return; converts to any Result<T> via cuda::std::unexpected.
static Error io(std::string message)
Fallible API result: cuda::std::expected<T, Error> with cuSBF factories.