Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
CNOCTAVE committed Nov 13, 2024
1 parent 7942f6a commit 7de5bb9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
# uncomment this on demand
- run: sudo chmod -R a+x octave_tar/inst
- run: tar --warning=no-file-changed --exclude='octave_zstd/.git' --exclude='octave_zstd/.github' -czvf octave_zstd.tar.gz octave_zstd
- run: gh release upload 1.0.3 octave_zstd.tar.gz --repo $GITHUB_REPOSITORY
- run: gh release upload 1.1.0 octave_zstd.tar.gz --repo $GITHUB_REPOSITORY
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: octave_zstd
Version: 1.0.3
Version: 1.1.0
Date: 2024-11-13
Author: various authors
Maintainer: Yu Hongbo <[email protected]>, CNOCTAVE <[email protected]>
Expand Down
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
** v1.1.0
Add .tar.zst format support.
tar_zstd_compress() for compress.
tar_zstd_decompress() for decompress.
Fix segment fault bug when call zstd_decompress()
function with unexist filename.
Fix incompletely decompress bug when a file has
multiple EOF char, e.g. tar file.
-------------------------------------------------------
** v1.0.3
chmod +x to src/configure
-------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<div id="online_install" class="title1 q-ma-md text-primary">在线安装</div>
<p class="q-ma-md">octave_zstd可以在线安装。</p>
<div class="text-h5 q-ma-md text-red-10">在线安装octave_zstd,代码如下:</div>
<p class="q-ma-md">>> pkg install 'https://github.com/CNOCTAVE/octave_zstd/releases/download/1.0.3/octave_zstd.tar.gz'</p>
<p class="q-ma-md">>> pkg install 'https://github.com/CNOCTAVE/octave_zstd/releases/download/1.1.0/octave_zstd.tar.gz'</p>
<q-separator></q-separator>
<div id="source_code_install" class="title1 q-ma-md text-primary">源码安装</div>
<p class="q-ma-md">octave_zstd可以直接使用tar包安装。</p>
Expand Down
36 changes: 17 additions & 19 deletions src/zstd_decompress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,27 @@ Always return @var{0}.\n\
error ("zstd_decompress: decompressed_filename should not be empty");
std::string compressed_filename = args(0).string_value ();
std::string decompressed_filename = args(1).string_value ();


std::ifstream compressed_file(compressed_filename, std::ios::binary);
std::vector<char> compressed_data((std::istreambuf_iterator<char>(compressed_file)), std::istreambuf_iterator<char>());
size_t compressed_size = compressed_data.size();

// 获取未压缩数据的大小(这通常需要外部信息,例如从文件头或其他元数据)
// 在这个示例中,我们假设我们有这个信息,或者使用一个足够大的缓冲区来容纳任何可能的解压缩数据。
// 为了简化,我们使用一个足够大的静态值。
// 将 std::vector<char> 转换为 const void*
const void* dataPtr = static_cast<const void*>(compressed_data.data());
size_t decompressed_size = ZSTD_getFrameContentSize(dataPtr, compressed_size);
std::vector<char> decompressed_buffer(decompressed_size);

size_t decompressed_ret = ZSTD_decompress(decompressed_buffer.data(), decompressed_buffer.size(),
compressed_data.data(), compressed_size);
if (ZSTD_isError(decompressed_ret)) {
try
{
std::vector<char> compressed_data((std::istreambuf_iterator<char>(compressed_file)), std::istreambuf_iterator<char>());
size_t compressed_size = compressed_data.size();
const void* dataPtr = static_cast<const void*>(compressed_data.data());
size_t decompressed_size = ZSTD_getFrameContentSize(dataPtr, compressed_size);
std::vector<char> decompressed_buffer(decompressed_size);
size_t decompressed_ret = ZSTD_decompress(decompressed_buffer.data(), decompressed_buffer.size(),
compressed_data.data(), compressed_size);
if (ZSTD_isError(decompressed_ret)) {
std::string concatenated = std::string("zstd_decompress: decompression failed: ") + std::string(ZSTD_getErrorName(decompressed_ret));
error ("%s", concatenated.c_str());
}
std::ofstream decompressed_file(decompressed_filename, std::ios::binary);
decompressed_file.write(decompressed_buffer.data(), decompressed_size);
}
catch(const std::exception& e)
{
error ("%s", e.what());
}

std::ofstream decompressed_file(decompressed_filename, std::ios::binary);
decompressed_file.write(decompressed_buffer.data(), decompressed_size);
retval = octave_value (0);

return retval;
Expand Down

0 comments on commit 7de5bb9

Please sign in to comment.