OpenMS
GzipIfstream.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 
13 #include <zlib.h>
14 
15 namespace OpenMS
16 {
20  class OPENMS_DLLAPI GzipIfstream
21  {
22 public:
25 
27  explicit GzipIfstream(const char * filename);
28 
30  virtual ~GzipIfstream();
31 
46  size_t read(char * s, size_t n);
47 
53  bool streamEnd() const;
54 
58  bool isOpen() const;
59 
65  void open(const char * filename);
66 
70  void close();
71 
72  /*
73  @brief updates crc32 check sum whether the buffer is corrupted
74  @note if this function is used it has to be called after every call of function read
75  @param s the buffer which will be checked
76  @param n the size of the buffer
77  *
78  //void updateCRC32(const char* s,const size_t n);
79 
80  *
81  @brief checks if data is corrupted after crc32 was computed
82  @note it can only be used if updateCRC32 was called after every call of function read
83  @return true if the buffer and hence the file is corrupted; no decompression is possible
84  *
85  //bool isCorrupted();
86 
87  //unsigned long Crc32_ComputeBuf( unsigned long inCrc32, const void *buf,
88 // size_t bufLen );*/
89 
90 protected:
91 
93  gzFile gzfile_;
95  int n_buffer_;
97  int gzerror_;
100 
101  //needed if one wants to know whether file is okay
102  //unsigned long original_crc;
103  //needed if one wants to know whether file is okay
104  //unsigned long crc;
105 
107  GzipIfstream(const GzipIfstream & bzip2);
109  };
110 
111  inline bool GzipIfstream::isOpen() const
112  {
113  return gzfile_ != nullptr;
114  }
115 
116  inline bool GzipIfstream::streamEnd() const
117  {
118  return stream_at_end_;
119  }
120 
121 /* inline bool GzipIfstream::isCorrupted()
122  {
123  std::cout<<"CRC"<<crc<<std::endl;
124  return (crc != original_crc);
125  }*/
126 
127 } //namespace OpenMS
Decompresses files which are compressed in the gzip format (*.gzip)
Definition: GzipIfstream.h:21
bool isOpen() const
returns whether a file is open.
Definition: GzipIfstream.h:111
int gzerror_
saves the last returned error by the read function
Definition: GzipIfstream.h:97
GzipIfstream & operator=(const GzipIfstream &bzip2)
int n_buffer_
counts the last read duffer
Definition: GzipIfstream.h:95
gzFile gzfile_
a gzFile object(void*) . Necessary for decompression
Definition: GzipIfstream.h:93
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: GzipIfstream.h:99
GzipIfstream(const char *filename)
Detailed constructor with filename.
GzipIfstream(const GzipIfstream &bzip2)
not implemented
size_t read(char *s, size_t n)
Reads n bytes from the bzip2 compressed file into buffer s.
GzipIfstream()
Default Constructor.
virtual ~GzipIfstream()
Destructor.
bool streamEnd() const
indicates whether the read function can be used safely
Definition: GzipIfstream.h:116
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22