PackageFileHeapAccessorBase: small refactoring
* Pull method DecompressChunkData() out of ReadAndDecompressChunkData() for potential reuse. * Also fix/improve some error output strings.
This commit is contained in:
@@ -63,6 +63,11 @@ protected:
|
|||||||
size_t uncompressedSize,
|
size_t uncompressedSize,
|
||||||
void* compressedDataBuffer,
|
void* compressedDataBuffer,
|
||||||
void* uncompressedDataBuffer);
|
void* uncompressedDataBuffer);
|
||||||
|
status_t DecompressChunkData(
|
||||||
|
void* compressedDataBuffer,
|
||||||
|
size_t compressedSize,
|
||||||
|
void* uncompressedDataBuffer,
|
||||||
|
size_t uncompressedSize);
|
||||||
status_t ReadFileData(uint64 offset, void* buffer,
|
status_t ReadFileData(uint64 offset, void* buffer,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
|
|||||||
@@ -201,18 +201,29 @@ PackageFileHeapAccessorBase::ReadAndDecompressChunkData(uint64 offset,
|
|||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
return DecompressChunkData(compressedDataBuffer, compressedSize,
|
||||||
|
uncompressedDataBuffer, uncompressedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PackageFileHeapAccessorBase::DecompressChunkData(void* compressedDataBuffer,
|
||||||
|
size_t compressedSize, void* uncompressedDataBuffer,
|
||||||
|
size_t uncompressedSize)
|
||||||
|
{
|
||||||
size_t actualSize;
|
size_t actualSize;
|
||||||
error = ZlibDecompressor::DecompressSingleBuffer(compressedDataBuffer,
|
status_t error = ZlibDecompressor::DecompressSingleBuffer(
|
||||||
compressedSize, uncompressedDataBuffer, uncompressedSize, actualSize);
|
compressedDataBuffer, compressedSize, uncompressedDataBuffer,
|
||||||
|
uncompressedSize, actualSize);
|
||||||
if (error != B_OK) {
|
if (error != B_OK) {
|
||||||
fErrorOutput->PrintError("Failed to decompress data chunk: %s\n",
|
fErrorOutput->PrintError("Failed to decompress chunk data: %s\n",
|
||||||
strerror(error));
|
strerror(error));
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actualSize != uncompressedSize) {
|
if (actualSize != uncompressedSize) {
|
||||||
fErrorOutput->PrintError("Failed to decompress data chunk: chunk "
|
fErrorOutput->PrintError("Failed to decompress chunk data: size "
|
||||||
"size mismatch\n");
|
"mismatch\n");
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,13 +237,13 @@ PackageFileHeapAccessorBase::ReadFileData(uint64 offset, void* buffer,
|
|||||||
{
|
{
|
||||||
ssize_t bytesRead = pread(fFD, buffer, size, fHeapOffset + (off_t)offset);
|
ssize_t bytesRead = pread(fFD, buffer, size, fHeapOffset + (off_t)offset);
|
||||||
if (bytesRead < 0) {
|
if (bytesRead < 0) {
|
||||||
fErrorOutput->PrintError("_ReadData(%" B_PRIu64 "%p, %zu) failed to "
|
fErrorOutput->PrintError("ReadFileData(%" B_PRIu64 "%p, %zu) failed to "
|
||||||
"read data: %s\n", offset, buffer, size, strerror(errno));
|
"read data: %s\n", offset, buffer, size, strerror(errno));
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
if ((size_t)bytesRead != size) {
|
if ((size_t)bytesRead != size) {
|
||||||
fErrorOutput->PrintError("_ReadData(%" B_PRIu64 "%p, %zu) failed to "
|
fErrorOutput->PrintError("ReadFileData(%" B_PRIu64 ", %p, %zu) could "
|
||||||
"read all data\n", offset, buffer, size);
|
"read only %zd bytes\n", offset, buffer, size, bytesRead);
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user