Go to the documentation of this file.
19 #ifndef OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
20 #define OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
23 #include <tbb/spin_mutex.h>
28 class TestStreamCompression;
33 namespace 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);
118 std::streamoff filepos;
119 long compressedBytes;
120 long uncompressedBytes;
124 using Ptr = std::shared_ptr<Page>;
137 const char*
buffer(
const int index)
const;
151 void copy(
const std::unique_ptr<
char[]>& temp,
int pageSize);
154 void decompress(
const std::unique_ptr<
char[]>& temp);
159 std::unique_ptr<Info> mInfo = std::unique_ptr<Info>(
new Info);
160 std::unique_ptr<char[]> mData;
161 tbb::spin_mutex mMutex;
170 #if OPENVDB_ABI_VERSION_NUMBER >= 6
171 using Ptr = std::unique_ptr<PageHandle>;
173 using Ptr = std::shared_ptr<PageHandle>;
186 int size()
const {
return mSize; }
190 std::unique_ptr<char[]>
read();
196 friend class ::TestStreamCompression;
211 using Ptr = std::shared_ptr<PagedInputStream>;
235 int mUncompressedBytes = 0;
236 std::istream* mIs =
nullptr;
238 bool mSizeOnly =
false;
248 using Ptr = std::shared_ptr<PagedOutputStream>;
271 void compressAndWrite(
const char* buffer,
size_t size);
274 void resize(
size_t size);
276 std::unique_ptr<char[]> mData = std::unique_ptr<char[]>(
new char[
PageSize]);
277 std::unique_ptr<char[]> mCompressedData =
nullptr;
280 std::ostream* mOs =
nullptr;
281 bool mSizeOnly =
false;
289 #endif // OPENVDB_TOOLS_STREAM_COMPRESSION_HAS_BEEN_INCLUDED
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only reading size data.
Definition: StreamCompression.h:218
A Paging wrapper to std::istream that is responsible for reading from a given input stream and creati...
Definition: StreamCompression.h:209
OPENVDB_API bool bloscCanCompress()
Returns true if compression is available.
PagedOutputStream & write(const char *str, std::streamsize n)
Writes the given.
std::ostream & getOutputStream()
Set and get the output stream.
Definition: StreamCompression.h:259
PagedInputStream(std::istream &is)
OPENVDB_API std::unique_ptr< char[]> bloscCompress(const char *buffer, const size_t uncompressedBytes, size_t &compressedBytes, const bool resize=true)
Compress and return the heap-allocated compressed buffer.
void readBuffers(std::istream &, bool delayed)
Read the Page buffers. If delayed is true, stream pointers will be stored to load the data lazily.
void load() const
load the Page into memory
int size() const
Return the size of the buffer.
Definition: StreamCompression.h:186
PagedOutputStream(std::ostream &os)
static const int BLOSC_PAD_BYTES
Definition: StreamCompression.h:42
A Paging wrapper to std::ostream that is responsible for writing from a given output stream at interv...
Definition: StreamCompression.h:246
static const int BLOSC_MINIMUM_BYTES
Definition: StreamCompression.h:38
void setInputStream(std::istream &is)
Definition: StreamCompression.h:223
void flush()
Manually flushes the current page to disk if non-zero.
Stores a variable-size, compressed, delayed-load Page of data that is loaded into memory when accesse...
Definition: StreamCompression.h:112
OPENVDB_API std::unique_ptr< char[]> bloscDecompress(const char *buffer, const size_t expectedBytes, const bool resize=true)
Decompress and return the the heap-allocated uncompressed buffer.
OPENVDB_API size_t bloscCompressedSize(const char *buffer, const size_t uncompressedBytes)
Convenience wrapper to retrieve the compressed size of buffer when compressed.
PageHandle::Ptr createHandle(std::streamsize n)
Creates a PageHandle to access the next.
PagedInputStream()=default
A PageHandle holds a unique ptr to a Page and a specific stream pointer to a point within the decompr...
Definition: StreamCompression.h:168
std::istream & getInputStream()
Definition: StreamCompression.h:222
std::shared_ptr< PagedInputStream > Ptr
Definition: StreamCompression.h:211
Ptr copy()
Return a copy of this PageHandle.
Definition: StreamCompression.h:193
std::shared_ptr< T > SharedPtr
Definition: openvdb/Types.h:92
std::unique_ptr< char[]> read()
Read and return the buffer, loading and decompressing the Page if necessary.
long uncompressedBytes() const
Uncompressed bytes of the Paged data, available when the header has been read.
OPENVDB_API size_t bloscUncompressedSize(const char *buffer)
Retrieves the uncompressed size of buffer when uncompressed.
std::shared_ptr< Page > Ptr
Definition: StreamCompression.h:124
PageHandle(const Page::Ptr &page, const int index, const int size)
Create the page handle.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153
void setOutputStream(std::ostream &os)
Definition: StreamCompression.h:260
std::shared_ptr< PagedOutputStream > Ptr
Definition: StreamCompression.h:248
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...
Page & page()
Retrieve a reference to the stored page.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:101
const char * buffer(const int index) const
Retrieves a data pointer at the specific.
void readHeader(std::istream &)
Read the Page header.
static const int PageSize
Definition: StreamCompression.h:105
Definition: openvdb/Exceptions.h:13
SharedPtr< MappedFile > Ptr
Definition: io.h:136
bool isOutOfCore() const
Test if the data is out-of-core.
void setSizeOnly(bool sizeOnly)
Size-only mode tags the stream as only writing size data.
Definition: StreamCompression.h:255
bool sizeOnly() const
Definition: StreamCompression.h:256
std::unique_ptr< PageHandle > Ptr
Definition: StreamCompression.h:171
bool sizeOnly() const
Definition: StreamCompression.h:219