------------------------------------------------------------------------------
| 516 | |
| 517 | //------------------------------------------------------------------------------ |
| 518 | int vtkXMLDataParser::ReadCompressionHeader() |
| 519 | { |
| 520 | std::unique_ptr<vtkXMLDataHeader> ch(vtkXMLDataHeader::New(this->HeaderType, 3)); |
| 521 | |
| 522 | this->DataStream->StartReading(); |
| 523 | |
| 524 | // Read the standard part of the header. |
| 525 | size_t const headerSize = ch->DataSize(); |
| 526 | size_t r = this->DataStream->Read(ch->Data(), headerSize); |
| 527 | if (r < headerSize) |
| 528 | { |
| 529 | vtkErrorMacro("Error reading beginning of compression header. Read " |
| 530 | << r << " of " << headerSize << " bytes."); |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | // Byte swap the header to make sure the values are correct. |
| 535 | this->PerformByteSwap(ch->Data(), ch->WordCount(), ch->WordSize()); |
| 536 | |
| 537 | // Get the standard values. |
| 538 | this->NumberOfBlocks = size_t(ch->Get(0)); |
| 539 | this->BlockUncompressedSize = size_t(ch->Get(1)); |
| 540 | this->PartialLastBlockUncompressedSize = size_t(ch->Get(2)); |
| 541 | |
| 542 | // Allocate the size and offset parts of the header. |
| 543 | ch->Resize(this->NumberOfBlocks); |
| 544 | delete[] this->BlockCompressedSizes; |
| 545 | this->BlockCompressedSizes = nullptr; |
| 546 | delete[] this->BlockStartOffsets; |
| 547 | this->BlockStartOffsets = nullptr; |
| 548 | if (this->NumberOfBlocks > 0) |
| 549 | { |
| 550 | this->BlockCompressedSizes = new size_t[this->NumberOfBlocks]; |
| 551 | this->BlockStartOffsets = new vtkTypeInt64[this->NumberOfBlocks]; |
| 552 | |
| 553 | // Read the compressed block sizes. |
| 554 | size_t len = ch->DataSize(); |
| 555 | if (this->DataStream->Read(ch->Data(), len) < len) |
| 556 | { |
| 557 | vtkErrorMacro("Error reading compression header."); |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | // Byte swap the sizes to make sure the values are correct. |
| 562 | this->PerformByteSwap(ch->Data(), ch->WordCount(), ch->WordSize()); |
| 563 | } |
| 564 | |
| 565 | this->DataStream->EndReading(); |
| 566 | |
| 567 | // Use the compressed block sizes to calculate the starting offset |
| 568 | // of each block. |
| 569 | vtkTypeInt64 offset = 0; |
| 570 | for (size_t i = 0; i < this->NumberOfBlocks; ++i) |
| 571 | { |
| 572 | size_t const sz = size_t(ch->Get(i)); |
| 573 | this->BlockCompressedSizes[i] = sz; |
| 574 | this->BlockStartOffsets[i] = offset; |
| 575 | offset += sz; |
no test coverage detected