19#ifndef OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
20#define OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
23#include <tbb/spin_mutex.h>
28class TestStreamCompression;
33namespace compression {
61 const size_t bufferBytes,
const char* uncompressedBuffer,
const size_t uncompressedBytes);
72 const size_t uncompressedBytes,
size_t& compressedBytes,
const bool resize =
true);
88 const size_t bufferBytes,
const char* compressedBuffer);
98 const size_t expectedBytes,
const bool resize =
true);
116#ifdef OPENVDB_USE_DELAYED_LOADING
117 io::MappedFile::Ptr mappedFile;
120 std::streamoff filepos;
121 long compressedBytes;
122 long uncompressedBytes;
126 using Ptr = std::shared_ptr<Page>;
139 const char*
buffer(
const int index)
const;
153 void copy(
const std::unique_ptr<
char[]>& temp,
int pageSize);
156 void decompress(
const std::unique_ptr<
char[]>& temp);
161 std::unique_ptr<Info> mInfo = std::unique_ptr<Info>(
new Info);
162 std::unique_ptr<char[]> mData;
163 tbb::spin_mutex mMutex;
172 using Ptr = std::unique_ptr<PageHandle>;
184 int size()
const {
return mSize; }
188 std::unique_ptr<char[]>
read();
194 friend class ::TestStreamCompression;
209 using Ptr = std::shared_ptr<PagedInputStream>;
233 int mUncompressedBytes = 0;
234 std::istream* mIs =
nullptr;
236 bool mSizeOnly =
false;
246 using Ptr = std::shared_ptr<PagedOutputStream>;
269 void compressAndWrite(
const char* buffer,
size_t size);
272 void resize(
size_t size);
274 std::unique_ptr<char[]> mData = std::unique_ptr<char[]>(
new char[PageSize]);
275 std::unique_ptr<char[]> mCompressedData =
nullptr;
278 std::ostream* mOs =
nullptr;
279 bool mSizeOnly =
false;
A PageHandle holds a unique ptr to a Page and a specific stream pointer to a point within the decompr...
Definition: StreamCompression.h:170
std::unique_ptr< char[]> read()
Read and return the buffer, loading and decompressing the Page if necessary.
Page & page()
Retrieve a reference to the stored page.
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:172
PageHandle(const Page::Ptr &page, const int index, const int size)
Create the page handle.
Ptr copy()
Return a copy of this PageHandle.
Definition: StreamCompression.h:191
int size() const
Return the size of the buffer.
Definition: StreamCompression.h:184
Stores a variable-size, compressed, delayed-load Page of data that is loaded into memory when accesse...
Definition: StreamCompression.h:112
long uncompressedBytes() const
Uncompressed bytes of the Paged data, available when the header has been read.
void readHeader(std::istream &)
Read the Page header.
void load() const
load the Page into memory
bool isOutOfCore() const
Test if the data is out-of-core.
const char * buffer(const int index) const
Retrieves a data pointer at the specific.
std::shared_ptr< Page > Ptr
Definition: StreamCompression.h:126
void readBuffers(std::istream &, bool delayed)
Read the Page buffers. If delayed is true, stream pointers will be stored to load the data lazily.
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:207
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition: StreamCompression.h:216
PagedInputStream(std::istream &is)
PagedInputStream()=default
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
void setInputStream(std::istream &is)
Definition: StreamCompression.h:221
bool sizeOnly() const
Definition: StreamCompression.h:217
void read(PageHandle::Ptr &pageHandle, std::streamsize n, bool delayed=true)
Takes a pageHandle and updates the referenced page with the current stream pointer position and if de...
std::shared_ptr< PagedInputStream > Ptr
Definition: StreamCompression.h:209
std::istream & getInputStream()
Definition: StreamCompression.h:220
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:244
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition: StreamCompression.h:253
void setOutputStream(std::ostream &os)
Definition: StreamCompression.h:258
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:257
std::shared_ptr< PagedOutputStream > Ptr
Definition: StreamCompression.h:246
bool sizeOnly() const
Definition: StreamCompression.h:254
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
PagedOutputStream(std::ostream &os)
void flush()
Manually flushes the current page to disk if non-zero.
static const int PageSize
Definition: StreamCompression.h:105
static const int BLOSC_PAD_BYTES
Definition: StreamCompression.h:42
static const int BLOSC_MINIMUM_BYTES
Definition: StreamCompression.h:38
OPENVDB_API bool bloscCanCompress()
Returns true if compression is available.
OPENVDB_API void bloscDecompress(char *uncompressedBuffer, const size_t expectedBytes, const size_t bufferBytes, const char *compressedBuffer)
Decompress into the supplied buffer. Will throw if decompression fails or uncompressed buffer has ins...
OPENVDB_API size_t bloscUncompressedSize(const char *buffer)
Retrieves the uncompressed size of buffer when uncompressed.
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
OPENVDB_API void bloscCompress(char *compressedBuffer, size_t &compressedBytes, const size_t bufferBytes, const char *uncompressedBuffer, const size_t uncompressedBytes)
Compress into the supplied buffer.
std::shared_ptr< T > SharedPtr
Definition: Types.h:114
Definition: Exceptions.h:13
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212