diff options
| author | ruki <[email protected]> | 2022-05-08 23:24:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-08 23:24:03 +0800 |
| commit | c33af98d91f597ce330bc2aa5fe009bcd39425a9 (patch) | |
| tree | 952bcd07ee6cc09bcd9f9af04b477f5d5a9b6a7e | |
| parent | 3b1e2a5299a4c0e5f88798acf51fe74aed840081 (diff) | |
improve lz4
| -rw-r--r-- | xmake/core/compress/lz4.lua | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/xmake/core/compress/lz4.lua b/xmake/core/compress/lz4.lua index 2f7f4ed1d..73ba85fba 100644 --- a/xmake/core/compress/lz4.lua +++ b/xmake/core/compress/lz4.lua @@ -60,6 +60,9 @@ end -- @return the result data -- function lz4.decompress(data, opt) + if type(data) == "string" then + data = bytes(data) + end local datasize = data:size() local dataaddr = data:caddr() local result, errors = lz4._decompress(dataaddr, datasize) @@ -71,11 +74,11 @@ end -- compress file data function lz4.compress_file(srcpath, dstpath, opt) - local data, errors = io.readfile(srcpath) + local data, errors = io.readfile(srcpath, {encoding = "binary"}) if data then data, errors = lz4.compress(data, opt) if data then - return io.writefile(dstpath, data) + return io.writefile(dstpath, data, {encoding = "binary"}) end end return false, errors or "compress failed" @@ -83,11 +86,11 @@ end -- decompress file data function lz4.decompress_file(srcpath, dstpath, opt) - local data, errors = io.readfile(srcpath) + local data, errors = io.readfile(srcpath, {encoding = "binary"}) if data then data, errors = lz4.decompress(data, opt) if data then - return io.writefile(dstpath, data) + return io.writefile(dstpath, data, {encoding = "binary"}) end end return false, errors or "decompress failed" |
