NCBI C++ ToolKit
reader_zlib.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef READER_ZLIB__HPP_INCLUDED
2 #define READER_ZLIB__HPP_INCLUDED
3 
4 /* $Id: reader_zlib.hpp 77707 2017-05-03 12:47:35Z ivanov $
5  * ===========================================================================
6  * PUBLIC DOMAIN NOTICE
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  * ===========================================================================
26  *
27  * Author: Eugene Vasilchenko
28  *
29  * File Description: byte reader with gzip decompression
30  *
31  */
32 
33 #include <corelib/ncbiobj.hpp>
34 #include <util/bytesrc.hpp>
35 #include <memory>
36 
37 
38 /** @addtogroup Compression
39  *
40  * @{
41  */
42 
43 
45 
46 class CResultZBtSrcX;
47 class CResultZBtSrcRdr;
48 class CZipCompression;
49 
51 {
52 public:
54  ~CNlmZipBtRdr();
55 
56  enum EType {
59  eType_zlib
60  };
61 
62  virtual size_t Read(char* buffer, size_t bufferLength);
63  virtual bool Pushback(const char* data, size_t size);
64 
65 private:
68 
71  unique_ptr<CResultZBtSrcX> m_Decompressor;
72 };
73 
74 
76 {
77 public:
78  enum {
79  kInititialSize = 8192
80  };
81 
83  : m_Size(0), m_Array(0)
84  {
85  }
86  CDynamicCharArray(size_t size);
87  ~CDynamicCharArray(void);
88 
89  char* At(size_t pos) const
90  {
91  _ASSERT(m_Array && pos <= m_Size);
92  return m_Array + pos;
93  }
94  char* Alloc(size_t size);
95 
96 private:
97  size_t m_Size;
98  char* m_Array;
99 
100 private:
103 };
104 
105 
107 {
108 public:
109  /// Which of the objects (passed in the constructor) should be
110  /// deleted on this object's destruction.
111  enum EOwnership {
112  fOwnNone = 0,
113  fOwnReader = 1 << 1, // own the underlying reader
114  fOwnAll = fOwnReader
115  };
116  typedef int TOwnership; // bitwise OR of EOwnership
117 
118  enum {
119  kHeaderSize = 4
120  };
121  enum EHeader { // 4 bytes: "ZIP"
122  eHeaderNone, // no header, always decompress
123  eHeaderAlways, // read header, always decompress
124  eHeaderCheck // check header, decompress if present
125  };
126 
127  CNlmZipReader(IReader* reader,
128  TOwnership own = fOwnNone,
129  EHeader header = eHeaderCheck);
130  ~CNlmZipReader(void);
131 
132  virtual ERW_Result Read(void* buf,
133  size_t count,
134  size_t* bytes_read = 0);
135  virtual ERW_Result PendingCount(size_t* count);
136 
137 protected:
138  void x_StartPlain(void);
139  void x_StartDecompressor(void);
140  size_t x_ReadZipHeader(char* buffer);
141  ERW_Result x_DecompressBuffer(void);
142  ERW_Result x_Read(char* buffer, size_t count, size_t* bytes_read);
143 
144 private:
147 
152  size_t m_BufferPos;
153  size_t m_BufferEnd;
154  unique_ptr<CZipCompression> m_Decompressor;
156 };
157 
158 
160 
161 
162 /* @} */
163 
164 #endif // READER_ZLIB__HPP_INCLUDED
static void * Alloc(size_t size)
Definition: asntypes.cpp:59
CZipCompression –.
Definition: zlib.hpp:81
A very basic data-read interface.
const int kHeaderSize
char data[12]
Definition: iconv.c:80
CNlmZipReader(const CNlmZipReader &)
void operator=(const CDynamicCharArray &)
CRef< CByteSourceReader > m_Src
Definition: reader_zlib.hpp:69
unique_ptr< CZipCompression > m_Decompressor
IReader * m_Reader
const CNlmZipBtRdr & operator=(const CNlmZipBtRdr &)
CDynamicCharArray m_Compressed
TOwnership m_Own
CNlmZipBtRdr(const CNlmZipBtRdr &)
unique_ptr< CResultZBtSrcX > m_Decompressor
Definition: reader_zlib.hpp:71
char * At(size_t pos) const
Definition: reader_zlib.hpp:89
CDynamicCharArray m_Buffer
EHeader m_Header
const CNlmZipReader & operator=(const CNlmZipReader &)
EOwnership
Which of the objects (passed in the constructor) should be deleted on this object's destruction.
size_t m_BufferEnd
CDynamicCharArray(const CDynamicCharArray &)
size_t m_BufferPos
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual size_t Read(char *buffer, size_t bufferLength)=0
Read up to bufferLength bytes into buffer return amount of bytes read (if zero - see EndOfData())
virtual bool Pushback(const char *data, size_t size)
Definition: bytesrc.cpp:86
ERW_Result
Result codes for I/O operations.
char * buf
const struct ncbi::grid::netcache::search::fields::SIZE size
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
static pcre_uint8 * buffer
Definition: pcretest.c:1051
NCBI_XUTIL_EXPORT
Parameter to control printing diagnostic message about conversion of static array data from a differe...
Definition: static_set.hpp:72
#define _ASSERT
Modified on Sat Jul 13 13:37:55 2024 by modify_doxy.py rev. 669887