Generalized LZ-style decompression; extend MveDecoder to decode in-flight MVEs
This commit is contained in:
29
TreFile.cc
29
TreFile.cc
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "common.hh"
|
||||
#include "util.hh"
|
||||
#include "decompress.hh"
|
||||
#include "TreFile.hh"
|
||||
|
||||
struct TreHeader { // little endian
|
||||
@@ -293,22 +294,14 @@ size_t TreFile::findCRC_(uint32_t crc) const
|
||||
|
||||
void TreFile::dumpIdx_(std::string const& name, size_t table3Idx) const
|
||||
{
|
||||
uint32_t dataPtr, length;
|
||||
uint8_t flags;
|
||||
std::tie(dataPtr, length, flags) = table3_[table3Idx];
|
||||
auto obj = openIdx_(table3Idx);
|
||||
|
||||
if(flags&0x80)
|
||||
throw Exception{"Compressed TRE objects NYI"};
|
||||
|
||||
if ((dataPtr + length) > length_)
|
||||
throw FormatException{"length exceeds file size"};
|
||||
|
||||
FILEUPtr outFile{fopen(name.c_str(), "wb")};
|
||||
if (!outFile)
|
||||
throw POSIXException{errno, "Could not open " + name};
|
||||
|
||||
if (fwrite(base_+dataPtr, length, 1, outFile.get()) != 1)
|
||||
throw POSIXException{errno, "Could not write"};
|
||||
if (fwrite(obj.data(), obj.size(), 1, outFile.get()) != 1)
|
||||
throw POSIXException{errno, "Could not write"};
|
||||
}
|
||||
|
||||
TreFile::Object TreFile::openIdx_(size_t table3Idx) const
|
||||
@@ -316,15 +309,19 @@ TreFile::Object TreFile::openIdx_(size_t table3Idx) const
|
||||
uint32_t dataPtr, length;
|
||||
uint8_t flags;
|
||||
std::tie(dataPtr, length, flags) = table3_[table3Idx];
|
||||
|
||||
if(flags&0x80)
|
||||
throw Exception{"Compressed TRE objects NYI"};
|
||||
|
||||
if ((dataPtr + length) > length_)
|
||||
throw FormatException{"length exceeds file size"};
|
||||
|
||||
return Object(base_+dataPtr,
|
||||
length);
|
||||
if (flags&0x80) {
|
||||
if (flags&0x40) {
|
||||
return Object(decompressLZ(base_+dataPtr, length));
|
||||
} else
|
||||
throw Exception{"Compression type 0 NYI"};
|
||||
} else {
|
||||
return Object(base_+dataPtr,
|
||||
length);
|
||||
}
|
||||
}
|
||||
|
||||
TreFile::Stat TreFile::statIdx_(size_t table3Idx) const
|
||||
|
||||
Reference in New Issue
Block a user