OpenMS
Loading...
Searching...
No Matches
ZipIfstream.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: Timo Sachsenberg $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h>
12
13#include <cstddef>
14
15namespace OpenMS
16{
36 class OPENMS_DLLAPI ZipIfstream
37 {
38public:
41
47 explicit ZipIfstream(const char* filename);
48
50 virtual ~ZipIfstream();
51
78 size_t read(char* s, size_t n);
79
85 bool streamEnd() const;
86
92 bool isOpen() const;
93
117 void open(const char* filename);
118
120 void close();
121
122 ZipIfstream(const ZipIfstream&) = delete;
126
127protected:
128 void* zip_archive_ = nullptr;
129 void* zip_entry_ = nullptr;
130 bool stream_at_end_ = true;
131 };
132
133 inline bool ZipIfstream::isOpen() const
134 {
135 return zip_entry_ != nullptr;
136 }
137
138 inline bool ZipIfstream::streamEnd() const
139 {
140 return stream_at_end_;
141 }
142
143} // namespace OpenMS
Streaming reader for the single non-directory entry of a ZIP archive.
Definition ZipIfstream.h:37
bool isOpen() const
Whether an archive entry is currently open for reading.
Definition ZipIfstream.h:133
ZipIfstream(const char *filename)
Construct and open filename in one step; see open for the exact behaviour and exception set.
void * zip_entry_
Opaque libzip zip_file_t* handle for the currently streamed entry; nullptr when no entry is open.
Definition ZipIfstream.h:129
virtual ~ZipIfstream()
Destructor; closes the archive and the entry handle.
ZipIfstream & operator=(const ZipIfstream &)=delete
void open(const char *filename)
Open filename and select its single non-directory entry for reading.
void close()
Close the currently open archive (no-op if none is open). After the call, isOpen returns false and st...
bool stream_at_end_
true once the stream has been closed (either explicitly via close or implicitly because the entry was...
Definition ZipIfstream.h:130
size_t read(char *s, size_t n)
Read up to n decompressed bytes from the open entry into s.
ZipIfstream(ZipIfstream &&)=delete
ZipIfstream()
Default constructor; leaves the instance in a closed state (isOpen returns false, streamEnd returns t...
ZipIfstream(const ZipIfstream &)=delete
bool streamEnd() const
Whether the stream has been closed (end of entry reached or no archive opened).
Definition ZipIfstream.h:138
ZipIfstream & operator=(ZipIfstream &&)=delete
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19