OpenMS
Loading...
Searching...
No Matches
Bzip2Ifstream.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: David Wojnar $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h>
12#include <cstddef> // for size_t
13#include <cstdio> // for std::FILE (used to come in through <bzlib.h>)
14#include <istream>
15
16// <bzlib.h> is deliberately not included here: bzip2 is a PRIVATE dependency of
17// libOpenMS, so no installed header may require its include directory. The only
18// bzip2 type this class needs is BZFILE, which bzlib defines as `typedef void
19// BZFILE;`, so the handle is stored as a void* below. Bzip2Ifstream.cpp includes
20// <bzlib.h> and does the conversions.
21
22namespace OpenMS
23{
39 class OPENMS_DLLAPI Bzip2Ifstream
40 {
41public:
44
57 explicit Bzip2Ifstream(const char * filename);
58
60 virtual ~Bzip2Ifstream();
61
82 size_t read(char * s, size_t n);
83
89 bool streamEnd() const;
90
96 bool isOpen() const;
97
108 void open(const char * filename);
109
111 void close();
112
113protected:
115 std::FILE * file_;
121 size_t n_buffer_;
126
127 //not implemented
130 };
131
132 //return bzip2file???!!!!????
133 inline bool Bzip2Ifstream::isOpen() const
134 {
135 return file_ != nullptr;
136 }
137
138 inline bool Bzip2Ifstream::streamEnd() const
139 {
140 return stream_at_end_;
141 }
142
143} //namespace OpenMS
Streaming decompressor for bzip2 (.bz2) files.
Definition Bzip2Ifstream.h:40
bool isOpen() const
Whether a file is currently open for reading.
Definition Bzip2Ifstream.h:133
Bzip2Ifstream(const char *filename)
Construct and open filename for reading in one step.
Bzip2Ifstream(const Bzip2Ifstream &bzip2)
int bzerror_
Most recent bzip2 status code returned to the read API.
Definition Bzip2Ifstream.h:123
std::FILE * file_
Underlying std::FILE handle used to feed the bzip2 reader; nullptr when no file is open.
Definition Bzip2Ifstream.h:115
Bzip2Ifstream()
Default constructor; leaves the instance in a closed state (isOpen returns false, streamEnd returns t...
void open(const char *filename)
Open filename for reading; closes the currently open file first.
void close()
Close the currently open file (no-op if none is open). After the call, isOpen returns false and strea...
bool stream_at_end_
true once the stream has been closed (either explicitly via close or implicitly because the end of th...
Definition Bzip2Ifstream.h:125
size_t read(char *s, size_t n)
Read up to n decompressed bytes into s.
virtual ~Bzip2Ifstream()
Destructor; closes the bzip2 reader and the underlying file handle.
size_t n_buffer_
Number of bytes produced by the most recent read call.
Definition Bzip2Ifstream.h:121
Bzip2Ifstream & operator=(const Bzip2Ifstream &bzip2)
void * bzip2file_
Definition Bzip2Ifstream.h:119
bool streamEnd() const
Whether the stream has been closed (end of file reached or no file opened).
Definition Bzip2Ifstream.h:138
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19