MCPcopy Create free account
hub / github.com/ImageEngine/cortex / decompress

Function decompress

src/IECore/StreamIndexedIO.cpp:491–529  ·  view source on GitHub ↗

decompress a memory buffer which is formed by a number of blosc compressed blocks returns the number of compression blocks 'outputBuffer' contains the decompressed data and is resized in this function if not large enough.

Source from the content-addressed store, hash-verified

489/// returns the number of compression blocks
490/// 'outputBuffer' contains the decompressed data and is resized in this function if not large enough.
491size_t decompress( const char *data, size_t size, std::vector<char> &outputBuffer, int threadCount )
492{
493 std::vector<std::pair<size_t, size_t>> blockSizes;
494 size_t totalDecompressedSize = 0;
495 size_t compressedBytesRead = 0;
496
497 while( compressedBytesRead < size )
498 {
499 size_t compressedNumBytes = 0, decompressedNumBytes = 0, blockSize = 0;
500 blosc_cbuffer_sizes( &data[compressedBytesRead], &decompressedNumBytes, &compressedNumBytes, &blockSize );
501
502 blockSizes.push_back( std::make_pair( compressedNumBytes, decompressedNumBytes ) );
503 totalDecompressedSize += decompressedNumBytes;
504 compressedBytesRead += compressedNumBytes;
505 }
506
507 if( outputBuffer.size() < totalDecompressedSize )
508 {
509 std::vector<char> b ( totalDecompressedSize );
510 outputBuffer.swap( b );
511 }
512
513 compressedBytesRead = 0;
514 size_t decompressedBytesWritten = 0;
515 for( const auto &blockSize : blockSizes )
516 {
517 int bloscResult = blosc_decompress_ctx( &data[compressedBytesRead], &outputBuffer[decompressedBytesWritten], blockSize.second, threadCount );
518
519 if( bloscResult <= 0 )
520 {
521 throw IECore::IOException( "StreamIndexedIO (decompress) - Corrupted compressed archive" );
522 }
523
524 compressedBytesRead += blockSize.first;
525 decompressedBytesWritten += blockSize.second;
526 }
527
528 return blockSizes.size();
529}
530
531} // namespace
532

Callers 2

openStreamMethod · 0.85
readNodeFromSubIndexMethod · 0.85

Calls 2

IOExceptionFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected