OpenMS
Loading...
Searching...
No Matches
GzipIfstream.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
13#include <cstddef> // for size_t (used to come in through <zlib.h>)
14
15// <zlib.h> is deliberately not included here: zlib is a PRIVATE dependency of
16// libOpenMS, so no installed header may require its include directory. The only
17// zlib type this class needs is gzFile, which both zlib and zlib-ng's drop-in
18// compatibility header declare as `typedef struct gzFile_s *gzFile;`, so a
19// forward declaration of that opaque struct is enough. GzipIfstream.cpp includes
20// <zlib.h> and calls the API.
21struct gzFile_s;
22
23namespace OpenMS
24{
28 class OPENMS_DLLAPI GzipIfstream
29 {
30public:
33
35 explicit GzipIfstream(const char * filename);
36
38 virtual ~GzipIfstream();
39
54 size_t read(char * s, size_t n);
55
61 bool streamEnd() const;
62
66 bool isOpen() const;
67
73 void open(const char * filename);
74
78 void close();
79
80 /*
81 @brief updates crc32 check sum whether the buffer is corrupted
82 @note if this function is used it has to be called after every call of function read
83 @param[in] s the buffer which will be checked
84 @param[in] n the size of the buffer
85 *
86 //void updateCRC32(const char* s,const size_t n);
87
88 *
89 @brief checks if data is corrupted after crc32 was computed
90 @note it can only be used if updateCRC32 was called after every call of function read
91 @return true if the buffer and hence the file is corrupted; no decompression is possible
92 *
93 //bool isCorrupted();
94
95 //unsigned long Crc32_ComputeBuf( unsigned long inCrc32, const void *buf,
96// size_t bufLen );*/
97
98protected:
99
103 gzFile_s * gzfile_;
110
111 //needed if one wants to know whether file is okay
112 //unsigned long original_crc;
113 //needed if one wants to know whether file is okay
114 //unsigned long crc;
115
119 };
120
121 inline bool GzipIfstream::isOpen() const
122 {
123 return gzfile_ != nullptr;
124 }
125
126 inline bool GzipIfstream::streamEnd() const
127 {
128 return stream_at_end_;
129 }
130
131/* inline bool GzipIfstream::isCorrupted()
132 {
133 std::cout<<"CRC"<<crc<<std::endl;
134 return (crc != original_crc);
135 }*/
136
137} //namespace OpenMS
Decompresses files which are compressed in the gzip format (*.gzip)
Definition GzipIfstream.h:29
bool isOpen() const
returns whether a file is open.
Definition GzipIfstream.h:121
int gzerror_
saves the last returned error by the read function
Definition GzipIfstream.h:107
int n_buffer_
counts the last read duffer
Definition GzipIfstream.h:105
GzipIfstream & operator=(const GzipIfstream &bzip2)
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:109
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.
gzFile_s * gzfile_
Definition GzipIfstream.h:103
bool streamEnd() const
indicates whether the read function can be used safely
Definition GzipIfstream.h:126
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19