diff options
| author | ruki <[email protected]> | 2022-05-10 22:42:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-10 22:42:46 +0800 |
| commit | cbde899071a43595d8cb0e61b1271fb231838025 (patch) | |
| tree | 591ee8314854973faa2e458db5d3563d770d8334 /core/src | |
| parent | bee9295b88b17adb7b7bec2c7d26592377892ceb (diff) | |
modify decompress
Diffstat (limited to 'core/src')
| -rw-r--r-- | core/src/xmake/lz4/decompress_file.c | 16 | ||||
| -rw-r--r-- | core/src/xmake/lz4/prefix.h | 19 |
2 files changed, 23 insertions, 12 deletions
diff --git a/core/src/xmake/lz4/decompress_file.c b/core/src/xmake/lz4/decompress_file.c index d0f9b27b7..0aa58ccf3 100644 --- a/core/src/xmake/lz4/decompress_file.c +++ b/core/src/xmake/lz4/decompress_file.c @@ -55,21 +55,27 @@ tb_int_t xm_lz4_decompress_file(lua_State* lua) { tb_bool_t write_ok = tb_false; tb_byte_t idata[TB_STREAM_BLOCK_MAXN]; + tb_byte_t odata[TB_STREAM_BLOCK_MAXN]; while (!tb_stream_beof(istream)) { write_ok = tb_false; tb_long_t ireal = (tb_long_t)tb_stream_read(istream, idata, sizeof(idata)); if (ireal > 0) { - tb_byte_t* odata = tb_null; - tb_long_t oreal = xm_lz4_dstream_decompress(stream_lz4, idata, ireal, &odata); - tb_assert_and_check_break(oreal >= 0); - if (oreal > 0) + tb_long_t r = xm_lz4_dstream_write(stream_lz4, idata, ireal); + tb_assert_and_check_break(r >= 0); + tb_check_continue(r > 0); + + tb_long_t oreal; + while ((oreal = xm_lz4_dstream_read(stream_lz4, odata, sizeof(odata))) > 0) { - tb_assert_and_check_break(odata); if (!tb_stream_bwrit(ostream, odata, oreal)) + { + oreal = -1; break; + } } + tb_assert_and_check_break(oreal >= 0); } else break; write_ok = tb_true; diff --git a/core/src/xmake/lz4/prefix.h b/core/src/xmake/lz4/prefix.h index 342269a4b..6c429a249 100644 --- a/core/src/xmake/lz4/prefix.h +++ b/core/src/xmake/lz4/prefix.h @@ -53,7 +53,6 @@ typedef struct __xm_lz4_dstream_t tb_size_t buffer_maxn; tb_size_t header_size; LZ4_byte header[LZ4F_HEADER_SIZE_MAX]; - LZ4_byte output[TB_STREAM_BLOCK_MAXN]; }xm_lz4_dstream_t; /* ////////////////////////////////////////////////////////////////////////////////////// @@ -179,10 +178,10 @@ static __tb_inline__ xm_lz4_dstream_t* xm_lz4_dstream_init() return stream; } -static __tb_inline__ tb_long_t xm_lz4_dstream_decompress(xm_lz4_dstream_t* stream, tb_byte_t const* idata, tb_size_t isize, tb_byte_t** podata) +static __tb_inline__ tb_long_t xm_lz4_dstream_write(xm_lz4_dstream_t* stream, tb_byte_t const* idata, tb_size_t isize) { // check - tb_assert_and_check_return_val(stream && stream->dctx && idata && isize && podata, -1); + tb_assert_and_check_return_val(stream && stream->dctx && idata && isize, -1); // read header first const tb_size_t header_size = sizeof(stream->header); @@ -235,11 +234,19 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_decompress(xm_lz4_dstream_t* strea // append the input data tb_memcpy(stream->buffer + stream->buffer_size, idata, isize); stream->buffer_size += isize; + return isize; +} + +static __tb_inline__ tb_long_t xm_lz4_dstream_read(xm_lz4_dstream_t* stream, tb_byte_t* odata, tb_size_t omaxn) +{ + // check + tb_assert_and_check_return_val(stream && stream->dctx && stream->buffer && odata && omaxn, -1); + tb_check_return_val(stream->buffer_size, 0); // do decompress size_t srcsize = stream->buffer_size; - size_t dstsize = sizeof(stream->output); - tb_size_t ret = LZ4F_decompress(stream->dctx, stream->output, &dstsize, stream->buffer, &srcsize, tb_null); + size_t dstsize = omaxn; + tb_size_t ret = LZ4F_decompress(stream->dctx, odata, &dstsize, stream->buffer, &srcsize, tb_null); if (LZ4F_isError(ret)) return -1; @@ -247,8 +254,6 @@ static __tb_inline__ tb_long_t xm_lz4_dstream_decompress(xm_lz4_dstream_t* strea if (srcsize < stream->buffer_size) tb_memmov(stream->buffer, stream->buffer + srcsize, stream->buffer_size - srcsize); stream->buffer_size -= srcsize; - - *podata = stream->output; return dstsize; } |
