OpenMS
Bzip2Ifstream.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- 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 <bzlib.h>
13 #include <istream>
14 
15 namespace OpenMS
16 {
20  class OPENMS_DLLAPI Bzip2Ifstream
21  {
22 public:
26  explicit Bzip2Ifstream(const char * filename);
28  virtual ~Bzip2Ifstream();
29 
44  size_t read(char * s, size_t n);
45 
51  bool streamEnd() const;
52 
56  bool isOpen() const;
57 
62  void open(const char * filename);
63 
67  void close();
68 
69 protected:
71  FILE * file_;
73  BZFILE * bzip2file_;
75  size_t n_buffer_;
77  int bzerror_;
80 
81  //not implemented
82  Bzip2Ifstream(const Bzip2Ifstream & bzip2);
84  };
85 
86  //return bzip2file???!!!!????
87  inline bool Bzip2Ifstream::isOpen() const
88  {
89  return file_ != nullptr;
90  }
91 
92  inline bool Bzip2Ifstream::streamEnd() const
93  {
94  return stream_at_end_;
95  }
96 
97 } //namespace OpenMS
Decompresses files which are compressed in the bzip2 format (*.bz2)
Definition: Bzip2Ifstream.h:21
bool isOpen() const
returns whether a file is open.
Definition: Bzip2Ifstream.h:87
Bzip2Ifstream(const char *filename)
Detailed constructor with filename.
Bzip2Ifstream(const Bzip2Ifstream &bzip2)
int bzerror_
saves the last returned error by the read function
Definition: Bzip2Ifstream.h:77
Bzip2Ifstream & operator=(const Bzip2Ifstream &bzip2)
Bzip2Ifstream()
Default Constructor.
void open(const char *filename)
opens a file for reading (decompression)
void close()
closes current file.
bool stream_at_end_
true if end of file is reached
Definition: Bzip2Ifstream.h:79
FILE * file_
pointer to a FILE object. Necessary for opening the file
Definition: Bzip2Ifstream.h:71
size_t read(char *s, size_t n)
Reads n bytes from the bzip2 compressed file into buffer s.
virtual ~Bzip2Ifstream()
Destructor.
BZFILE * bzip2file_
a pointer to a BZFILE object. Necessary for decompression
Definition: Bzip2Ifstream.h:73
size_t n_buffer_
counts the last read buffer
Definition: Bzip2Ifstream.h:75
bool streamEnd() const
indicates whether the read function can be used safely
Definition: Bzip2Ifstream.h:92
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22