Skip to content

Commit

Permalink
zstd ZSTD_getFrameContentSize can return decompress size
Browse files Browse the repository at this point in the history
zstd HEAD include optional field, which show original filesize.
The default yocto image set this optional field.
So needn't guess decopressed file size.

Signed-off-by: Frank Li <[email protected]>
  • Loading branch information
nxpfrankli committed Aug 23, 2022
1 parent d539877 commit ed48c51
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions libuuu/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1109,16 +1109,31 @@ int FSzstd::Decompress(const string& backfile, shared_ptr<FileBuffer>outp)
{
return -1;
}
if (outp->reserve(inp->size() * 16))
return -1;

shared_ptr<FileBuffer> buff;
buff = inp->request_data(0, 0x1000);
size_t decompress_size = ZSTD_getFrameContentSize(buff->data(), 0x1000);

if (decompress_size < inp->size())
{
decompress_size = inp->size() * 16;
if (outp->reserve(decompress_size))
return -1;
}
else
{
atomic_fetch_or(&outp->m_dataflags, FILEBUFFER_FLAG_KNOWN_SIZE);
if (outp->resize(decompress_size))
return -1;

}

size_t offset = 0;
uuu_notify ut;
ut.type = uuu_notify::NOTIFY_DECOMPRESS_START;
ut.str = (char*)backfile.c_str();
call_notify(ut);
size_t const toRead = ZSTD_DStreamInSize();
std::shared_ptr<FileBuffer> buff;

while ((buff = inp->request_data(offset, toRead)))
{
Expand Down

0 comments on commit ed48c51

Please sign in to comment.