summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-11 00:59:44 +0800
committerruki <[email protected]>2022-05-11 00:59:44 +0800
commit86868ef785f49b2380e758932612c11cf9800920 (patch)
tree918982e1efca270b02c6a5f429cec4b6becd7924
parentcf981aa623d6511a4b7f8694b09b4c1192f2dd17 (diff)
add stream wrap
-rw-r--r--xmake/core/compress/lz4.lua16
-rw-r--r--xmake/core/sandbox/modules/import/core/compress/lz4.lua36
2 files changed, 52 insertions, 0 deletions
diff --git a/xmake/core/compress/lz4.lua b/xmake/core/compress/lz4.lua
index 88b854760..32a215af0 100644
--- a/xmake/core/compress/lz4.lua
+++ b/xmake/core/compress/lz4.lua
@@ -54,6 +54,14 @@ function _cstream:cdata()
return self._HANDLE
end
+-- ensure the socket is opened
+function _cstream:_ensure_opened()
+ if not self:cdata() then
+ return false, string.format("%s: has been closed!", self)
+ end
+ return true
+end
+
-- tostring(stream)
function _cstream:__tostring()
return string.format("<lz4/cstream: %s>", self:cdata())
@@ -79,6 +87,14 @@ function _dstream:cdata()
return self._HANDLE
end
+-- ensure the socket is opened
+function _dstream:_ensure_opened()
+ if not self:cdata() then
+ return false, string.format("%s: has been closed!", self)
+ end
+ return true
+end
+
-- tostring(stream)
function _dstream:__tostring()
return string.format("<lz4/dstream: %s>", self:cdata())
diff --git a/xmake/core/sandbox/modules/import/core/compress/lz4.lua b/xmake/core/sandbox/modules/import/core/compress/lz4.lua
index f450609f8..a93c9aa65 100644
--- a/xmake/core/sandbox/modules/import/core/compress/lz4.lua
+++ b/xmake/core/sandbox/modules/import/core/compress/lz4.lua
@@ -57,6 +57,42 @@ function _dstream_wrap(instance)
return instance
end
+-- read data from stream
+function sandbox_core_compress_lz4_cstream.read(stream, buff, size, opt)
+ local real, data_or_errors = stream:_read(buff, size, opt)
+ if real < 0 and data_or_errors then
+ raise(data_or_errors)
+ end
+ return real, data_or_errors
+end
+
+-- write data to stream
+function sandbox_core_compress_lz4_cstream.write(stream, data, beof, opt)
+ local real, errors = stream:_write(data, beof, opt)
+ if real < 0 and errors then
+ raise(errors)
+ end
+ return real
+end
+
+-- read data from stream
+function sandbox_core_compress_lz4_dstream.read(stream, buff, size, opt)
+ local real, data_or_errors = stream:_read(buff, size, opt)
+ if real < 0 and data_or_errors then
+ raise(data_or_errors)
+ end
+ return real, data_or_errors
+end
+
+-- write data to stream
+function sandbox_core_compress_lz4_dstream.write(stream, data, beof, opt)
+ local real, errors = stream:_write(data, beof, opt)
+ if real < 0 and errors then
+ raise(errors)
+ end
+ return real
+end
+
-- compress frame data
function sandbox_core_compress_lz4.compress(data, opt)
local result, errors = lz4.compress(data, opt)