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.
| 489 | /// returns the number of compression blocks |
| 490 | /// 'outputBuffer' contains the decompressed data and is resized in this function if not large enough. |
| 491 | size_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 |
no test coverage detected