BeLzma.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 #include "BeSQLite.h"
10 
12 
13 //=======================================================================================
15 // @bsiclass Bentley Systems
16 //=======================================================================================
18 {
19  virtual ZipErrors _Write(void const* data, uint32_t size, uint32_t&bytesWritten) = 0;
20  virtual void _SetAlwaysFlush(bool flushOnEveryWrite) = 0;
21 };
22 
23 //=======================================================================================
25 // @bsiclass Bentley Systems
26 //=======================================================================================
28 {
29  virtual ZipErrors _Read(void* data, uint32_t size, uint32_t& actuallyRead) = 0;
30  virtual uint64_t _GetSize() = 0;
31 };
32 
33 //=======================================================================================
35 // @bsiclass Bentley Systems
36 //=======================================================================================
38 {
39 private:
40  BeFile m_file;
41  uint64_t m_fileSize;
42  uint64_t m_bytesRead;
43 
44 public:
45  virtual ~BeFileLzmaInStream() {}
46  BE_SQLITE_EXPORT StatusInt OpenInputFile(BeFileNameCR fileName);
47  BE_SQLITE_EXPORT ZipErrors _Read(void* data, uint32_t size, uint32_t& actuallyRead) override;
48  uint64_t _GetSize() override {return m_fileSize;}
49  uint64_t GetBytesRead() {return m_bytesRead;}
50  BeFile& GetBeFile() {return m_file;}
51 };
52 
53 //=======================================================================================
55 // @bsiclass Bentley Systems
56 //=======================================================================================
58 {
59 private:
60  BeFile m_file;
61  uint64_t m_bytesWritten;
62 
63 public:
64  virtual ~BeFileLzmaOutStream() {}
65  BE_SQLITE_EXPORT BeFileStatus CreateOutputFile(BeFileNameCR fileName, bool createAlways = true);
66  BE_SQLITE_EXPORT ZipErrors _Write(void const* data, uint32_t size, uint32_t& bytesWritten) override;
67  BE_SQLITE_EXPORT void _SetAlwaysFlush(bool flushOnEveryWrite) override;
68  uint64_t GetBytesWritten() {return m_bytesWritten;}
69  BeFile& GetBeFile() {return m_file;}
70 };
71 
72 //=======================================================================================
74 // @bsiclass Bentley Systems
75 //=======================================================================================
77 {
78 private:
79  uint32_t m_offset;
80  uint32_t m_size;
81  void const* m_data;
82 
83  uint32_t m_headerOffset;
84  uint32_t m_headerSize;
85  void const* m_headerData;
86 
87 public:
88  MemoryLzmaInStream(void const*data, uint32_t size)
89  {
90  SetData(data, size);
91  SetHeaderData(nullptr, 0);
92  }
93 
94  void SetData(void const* data, uint32_t size)
95  {
96  m_data = data;
97  m_size = size;
98  m_offset = 0;
99  }
100 
101  void SetHeaderData(void const* headerData, uint32_t headerSize)
102  {
103  m_headerData = headerData;
104  m_headerSize = headerSize;
105  m_headerOffset = 0;
106  }
107 
108  BE_SQLITE_EXPORT virtual ZipErrors _Read(void* data, uint32_t size, uint32_t& actuallyRead) override;
109  virtual uint64_t _GetSize() override { return m_size + m_headerSize; }
110 };
111 
112 //=======================================================================================
114 // @bsiclass Bentley Systems
115 //=======================================================================================
117 {
118 private:
119  bvector<Byte>& m_buffer;
120 
121 public:
122  MemoryLzmaOutStream(bvector<Byte>& v) : m_buffer(v) {}
123  virtual ~MemoryLzmaOutStream() {}
124 
125  BE_SQLITE_EXPORT ZipErrors _Write(void const* data, uint32_t writeSize, uint32_t& bytesWritten) override;
126  void _SetAlwaysFlush(bool flushOnEveryWrite) override {}
127 };
128 
129 //=======================================================================================
131 // @bsiclass Bentley Systems
132 //=======================================================================================
134 {
135 public:
136  struct Impl;
137 
138 private:
139  Impl* m_impl;
140 
141 public:
147  BE_SQLITE_EXPORT LzmaEncoder(uint32_t dictionarySize = 1 << 24, bool supportRandomAccess = false);
148 
150  BE_SQLITE_EXPORT ~LzmaEncoder();
151 
154  BE_SQLITE_EXPORT void SetProgressTracker(ICompressProgressTracker* progressTracker);
155 
157  void SetBlockSize(uint32_t blockSize);
158 
161  BE_SQLITE_EXPORT ZipErrors StartCompress(ILzmaOutputStream& outStream);
162 
167  BE_SQLITE_EXPORT ZipErrors CompressNextPage(void const* pData, int nData);
168 
170  BE_SQLITE_EXPORT ZipErrors FinishCompress();
171 
174 
176  BE_SQLITE_EXPORT ZipErrors CompressBuffer(bvector<Byte>& out, void const *input, uint32_t sizeInput);
177 };
178 
179 //=======================================================================================
181 // @bsiclass Bentley Systems
182 //=======================================================================================
184 {
185 public:
186  struct Impl;
187 
188 private:
189  Impl* m_impl;
190 
191 public:
194 
196  BE_SQLITE_EXPORT ~LzmaDecoder();
197 
200  BE_SQLITE_EXPORT void SetProgressTracker(ICompressProgressTracker* progressTracker);
201 
204  BE_SQLITE_EXPORT ZipErrors StartDecompress(ILzmaInputStream& inStream);
205 
211  BE_SQLITE_EXPORT ZipErrors DecompressNextPage(void* pData, int* pnData);
212 
214  BE_SQLITE_EXPORT void FinishDecompress();
215 
217  BE_SQLITE_EXPORT ZipErrors DecompressStream(ILzmaOutputStream& outStream, ILzmaInputStream& inStream);
218 
220  BE_SQLITE_EXPORT ZipErrors DecompressBuffer(bvector<Byte>&out, void const*inputBuffer, uint32_t inputSize);
221 };
222 
void SetData(void const *data, uint32_t size)
Definition: BeLzma.h:94
virtual uint64_t _GetSize() override
Definition: BeLzma.h:109
#define END_BENTLEY_SQLITE_NAMESPACE
Definition: BeSQLite.h:139
struct Bentley::BeFileName const & BeFileNameCR
Definition: Bentley.h:242
Utility to stream the output of LZMA routines to a file.
Definition: BeLzma.h:57
Interface to receive/write streamed Lzma output.
Definition: BeLzma.h:17
virtual ~BeFileLzmaOutStream()
Definition: BeLzma.h:64
virtual ~MemoryLzmaOutStream()
Definition: BeLzma.h:123
void _SetAlwaysFlush(bool flushOnEveryWrite) override
Definition: BeLzma.h:126
Utility to read and decompress streams in the LZMA format.
Definition: BeLzma.h:183
MemoryLzmaInStream(void const *data, uint32_t size)
Definition: BeLzma.h:88
Utility to stream the contents of a file to LZMA routines.
Definition: BeLzma.h:37
unsigned long long uint64_t
Definition: Bentley.r.h:95
uint64_t _GetSize() override
Definition: BeLzma.h:48
Utility to stream the contents of a memory buffer to LZMA routines.
Definition: BeLzma.h:76
uint64_t GetBytesRead()
Definition: BeLzma.h:49
Utility to stream the output of LZMA routines to a memory buffer.
Definition: BeLzma.h:116
#define BEGIN_BENTLEY_SQLITE_NAMESPACE
Definition: BeSQLite.h:138
#define BE_SQLITE_EXPORT
Definition: BeSQLite.h:124
void SetHeaderData(void const *headerData, uint32_t headerSize)
Definition: BeLzma.h:101
Defines a callback for providing information on the progress of a compress or decompress operation...
Definition: BeSQLite.h:1452
Interface to send/read streamed Lzma input.
Definition: BeLzma.h:27
virtual ~BeFileLzmaInStream()
Definition: BeLzma.h:45
int StatusInt
Definition: Bentley.h:222
BeFile provides a way to open a file and methods to access its contents and attributes.
Definition: BeFile.h:78
uint64_t GetBytesWritten()
Definition: BeLzma.h:68
MemoryLzmaOutStream(bvector< Byte > &v)
Definition: BeLzma.h:122
unsigned int uint32_t
Definition: Bentley.r.h:93
BeFile & GetBeFile()
Definition: BeLzma.h:69
BeFile & GetBeFile()
Definition: BeLzma.h:50
Utility to compress and write streams to the LZMA format.
Definition: BeLzma.h:133
size_type size() const
Definition: stdcxx/bstdmap.h:214
ZipErrors
Error values returned from the ZLib functions. See ZLib documentation for details.
Definition: BeSQLite.h:2692
BeFileStatus
The possible status returns for the BeFile methods.
Definition: BeFile.h:28

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.