diff options
| author | ruki <[email protected]> | 2022-05-08 19:31:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-08 19:31:42 +0800 |
| commit | 941676f28ac40dc8a3801ce2a8cc33a5afe00e0f (patch) | |
| tree | 6adf088080d0d9f78f9a5c845f73bb0697d7fa10 | |
| parent | 517b91f7101291627e992f587e382f930855c320 (diff) | |
add block compress wrap
| -rw-r--r-- | xmake/core/compress/lz4.lua | 45 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/compress/lz4.lua | 22 |
2 files changed, 61 insertions, 6 deletions
diff --git a/xmake/core/compress/lz4.lua b/xmake/core/compress/lz4.lua index c6fed7cf0..2ac5de7b3 100644 --- a/xmake/core/compress/lz4.lua +++ b/xmake/core/compress/lz4.lua @@ -32,7 +32,7 @@ lz4._decompress = lz4._decompress or lz4.decompress lz4._block_compress = lz4._block_compress or lz4.block_compress lz4._block_decompress = lz4._block_decompress or lz4.block_decompress --- compress data +-- compress frame data -- -- @param data the data -- @param opt the options @@ -47,12 +47,12 @@ function lz4.compress(data, opt) local dataaddr = data:caddr() local result, errors = lz4._compress(dataaddr, datasize) if not result then - return nil, errors or string.format("compress lz4 data failed, %s", errors or "unknown") + return nil, errors or string.format("compress frame data failed, %s", errors or "unknown") end return bytes(result) end --- decompres data +-- decompres frame data -- -- @param data the data -- @param opt the options @@ -64,7 +64,44 @@ function lz4.decompress(data, opt) local dataaddr = data:caddr() local result, errors = lz4._decompress(dataaddr, datasize) if not result then - return nil, string.format("decompress lz4 data failed, %s", errors or "unknown") + return nil, string.format("decompress frame data failed, %s", errors or "unknown") + end + return bytes(result) +end + +-- compress block data +-- +-- @param data the data +-- @param opt the options +-- +-- @return the result data +-- +function lz4.block_compress(data, opt) + if type(data) == "string" then + data = bytes(data) + end + local datasize = data:size() + local dataaddr = data:caddr() + local result, errors = lz4._block_compress(dataaddr, datasize) + if not result then + return nil, errors or string.format("compress block data failed, %s", errors or "unknown") + end + return bytes(result) +end + +-- decompres block data +-- +-- @param data the data +-- @param opt the options +-- +-- @return the result data +-- +function lz4.block_decompress(data, opt) + local datasize = data:size() + local dataaddr = data:caddr() + local result, errors = lz4._block_decompress(dataaddr, datasize) + if not result then + return nil, string.format("decompress block data failed, %s", errors or "unknown") end return bytes(result) end diff --git a/xmake/core/sandbox/modules/import/core/compress/lz4.lua b/xmake/core/sandbox/modules/import/core/compress/lz4.lua index d05c6a6fd..8f45d7a3a 100644 --- a/xmake/core/sandbox/modules/import/core/compress/lz4.lua +++ b/xmake/core/sandbox/modules/import/core/compress/lz4.lua @@ -25,7 +25,7 @@ local sandbox_core_compress_lz4 = sandbox_core_compress_lz4 or {} local lz4 = require("compress/lz4") local raise = require("sandbox/modules/raise") --- compress data +-- compress frame data function sandbox_core_compress_lz4.compress(data, opt) local result, errors = lz4.compress(data, opt) if not result and errors then @@ -34,7 +34,7 @@ function sandbox_core_compress_lz4.compress(data, opt) return result end --- decompress data +-- decompress frame data function sandbox_core_compress_lz4.decompress(data, opt) local result, errors = lz4.decompress(data, opt) if not result and errors then @@ -43,5 +43,23 @@ function sandbox_core_compress_lz4.decompress(data, opt) return result end +-- compress block data +function sandbox_core_compress_lz4.block_compress(data, opt) + local result, errors = lz4.block_compress(data, opt) + if not result and errors then + raise(errors) + end + return result +end + +-- decompress block data +function sandbox_core_compress_lz4.block_decompress(data, opt) + local result, errors = lz4.block_decompress(data, opt) + if not result and errors then + raise(errors) + end + return result +end + -- return module return sandbox_core_compress_lz4 |
