mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Fix LZMA compression for data blocks.
This commit is contained in:
11
src/write.c
11
src/write.c
@@ -290,7 +290,13 @@ int32_t aaruf_write_sector(void *context, uint64_t sector_address, bool negative
|
|||||||
ctx->currentBlockHeader.compression = None;
|
ctx->currentBlockHeader.compression = None;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
ctx->currentTrackType = Data;
|
ctx->currentTrackType = Data;
|
||||||
|
if(ctx->compression_enabled)
|
||||||
|
ctx->currentBlockHeader.compression = Lzma;
|
||||||
|
else
|
||||||
|
ctx->currentBlockHeader.compression = None;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t max_buffer_size = (1 << ctx->userDataDdtHeader.dataShift) * ctx->currentBlockHeader.sectorSize;
|
uint32_t max_buffer_size = (1 << ctx->userDataDdtHeader.dataShift) * ctx->currentBlockHeader.sectorSize;
|
||||||
TRACE("Setting max buffer size to %u bytes", max_buffer_size);
|
TRACE("Setting max buffer size to %u bytes", max_buffer_size);
|
||||||
@@ -1430,10 +1436,11 @@ int32_t aaruf_close_current_block(aaruformatContext *ctx)
|
|||||||
|
|
||||||
size_t dst_size = ctx->currentBlockHeader.length * 2;
|
size_t dst_size = ctx->currentBlockHeader.length * 2;
|
||||||
size_t props_size = LZMA_PROPERTIES_LENGTH;
|
size_t props_size = LZMA_PROPERTIES_LENGTH;
|
||||||
ctx->currentBlockHeader.cmpLength =
|
|
||||||
aaruf_lzma_encode_buffer(cmp_buffer, &dst_size, ctx->writingBuffer, ctx->currentBlockHeader.length,
|
aaruf_lzma_encode_buffer(cmp_buffer, &dst_size, ctx->writingBuffer, ctx->currentBlockHeader.length,
|
||||||
lzma_properties, &props_size, 9, ctx->lzma_dict_size, 4, 0, 2, 273, 8);
|
lzma_properties, &props_size, 9, ctx->lzma_dict_size, 4, 0, 2, 273, 8);
|
||||||
|
|
||||||
|
ctx->currentBlockHeader.cmpLength = (uint32_t)dst_size;
|
||||||
|
|
||||||
if(ctx->currentBlockHeader.cmpLength >= ctx->currentBlockHeader.length)
|
if(ctx->currentBlockHeader.cmpLength >= ctx->currentBlockHeader.length)
|
||||||
{
|
{
|
||||||
ctx->currentBlockHeader.compression = None;
|
ctx->currentBlockHeader.compression = None;
|
||||||
@@ -1490,7 +1497,7 @@ int32_t aaruf_close_current_block(aaruformatContext *ctx)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(fwrite(cmp_buffer, ctx->currentBlockHeader.cmpLength, 1, ctx->imageStream) == 1)
|
if(fwrite(cmp_buffer, ctx->currentBlockHeader.cmpLength, 1, ctx->imageStream) != 1)
|
||||||
{
|
{
|
||||||
free(cmp_buffer);
|
free(cmp_buffer);
|
||||||
return AARUF_ERROR_CANNOT_WRITE_BLOCK_DATA;
|
return AARUF_ERROR_CANNOT_WRITE_BLOCK_DATA;
|
||||||
|
|||||||
Reference in New Issue
Block a user