summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-05-11 00:07:02 +0800
committerruki <[email protected]>2022-05-11 00:07:02 +0800
commit2ff70579a8473302cec690f4651f9be865073833 (patch)
tree8fd87c37b55edeb33bbfdf9f11df6cff4f8f8bfa
parent815f15d955b3595349efd1429abbb9119b0fb043 (diff)
add compress stream
-rw-r--r--core/src/xmake/engine.c22
-rw-r--r--core/src/xmake/lz4/compress_stream_close.c56
-rw-r--r--core/src/xmake/lz4/compress_stream_open.c46
-rw-r--r--core/src/xmake/lz4/decompress_stream_close.c56
-rw-r--r--core/src/xmake/lz4/decompress_stream_open.c46
-rw-r--r--core/src/xmake/makefile6
6 files changed, 224 insertions, 8 deletions
diff --git a/core/src/xmake/engine.c b/core/src/xmake/engine.c
index b6e78970a..a5f767edf 100644
--- a/core/src/xmake/engine.c
+++ b/core/src/xmake/engine.c
@@ -196,6 +196,10 @@ tb_int_t xm_lz4_block_compress(lua_State* lua);
tb_int_t xm_lz4_block_decompress(lua_State* lua);
tb_int_t xm_lz4_compress_file(lua_State* lua);
tb_int_t xm_lz4_decompress_file(lua_State* lua);
+tb_int_t xm_lz4_compress_stream_open(lua_State* lua);
+tb_int_t xm_lz4_compress_stream_close(lua_State* lua);
+tb_int_t xm_lz4_decompress_stream_open(lua_State* lua);
+tb_int_t xm_lz4_decompress_stream_close(lua_State* lua);
// the windows functions
#ifdef TB_CONFIG_OS_WINDOWS
@@ -414,13 +418,17 @@ static luaL_Reg const g_base64_functions[] =
// the lz4 functions
static luaL_Reg const g_lz4_functions[] =
{
- { "compress", xm_lz4_compress }
-, { "decompress", xm_lz4_decompress }
-, { "block_compress", xm_lz4_block_compress }
-, { "block_decompress", xm_lz4_block_decompress }
-, { "compress_file", xm_lz4_compress_file }
-, { "decompress_file", xm_lz4_decompress_file }
-, { tb_null, tb_null }
+ { "compress", xm_lz4_compress }
+, { "decompress", xm_lz4_decompress }
+, { "block_compress", xm_lz4_block_compress }
+, { "block_decompress", xm_lz4_block_decompress }
+, { "compress_file", xm_lz4_compress_file }
+, { "decompress_file", xm_lz4_decompress_file }
+, { "compress_stream_open", xm_lz4_compress_stream_open }
+, { "compress_stream_close", xm_lz4_compress_stream_close }
+, { "decompress_stream_open", xm_lz4_decompress_stream_open }
+, { "decompress_stream_close",xm_lz4_decompress_stream_close }
+, { tb_null, tb_null }
};
// the string functions
diff --git a/core/src/xmake/lz4/compress_stream_close.c b/core/src/xmake/lz4/compress_stream_close.c
new file mode 100644
index 000000000..7bca6a0a7
--- /dev/null
+++ b/core/src/xmake/lz4/compress_stream_close.c
@@ -0,0 +1,56 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file compress_stream_close.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "compress_stream_close"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_lz4_compress_stream_close(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get the stream
+ xm_lz4_cstream_t* stream = (xm_lz4_cstream_t*)xm_lua_topointer(lua, 1);
+ tb_check_return_val(stream, 0);
+
+ // exit stream
+ xm_lz4_cstream_exit(stream);
+
+ // save result: ok
+ lua_pushboolean(lua, tb_true);
+ return 1;
+}
+
diff --git a/core/src/xmake/lz4/compress_stream_open.c b/core/src/xmake/lz4/compress_stream_open.c
new file mode 100644
index 000000000..f578bf5fc
--- /dev/null
+++ b/core/src/xmake/lz4/compress_stream_open.c
@@ -0,0 +1,46 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file compress_stream_open.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "compress_stream_open"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_lz4_compress_stream_open(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ xm_lz4_cstream_t* stream = xm_lz4_cstream_init();
+ if (stream) xm_lua_pushpointer(lua, (tb_pointer_t)stream);
+ lua_pushnil(lua);
+ return 1;
+}
+
diff --git a/core/src/xmake/lz4/decompress_stream_close.c b/core/src/xmake/lz4/decompress_stream_close.c
new file mode 100644
index 000000000..6b10bd3b0
--- /dev/null
+++ b/core/src/xmake/lz4/decompress_stream_close.c
@@ -0,0 +1,56 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file decompress_stream_close.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "decompress_stream_close"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_lz4_decompress_stream_close(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ // is pointer?
+ if (!xm_lua_ispointer(lua, 1))
+ return 0;
+
+ // get the stream
+ xm_lz4_dstream_t* stream = (xm_lz4_dstream_t*)xm_lua_topointer(lua, 1);
+ tb_check_return_val(stream, 0);
+
+ // exit stream
+ xm_lz4_dstream_exit(stream);
+
+ // save result: ok
+ lua_pushboolean(lua, tb_true);
+ return 1;
+}
+
diff --git a/core/src/xmake/lz4/decompress_stream_open.c b/core/src/xmake/lz4/decompress_stream_open.c
new file mode 100644
index 000000000..a1b930d61
--- /dev/null
+++ b/core/src/xmake/lz4/decompress_stream_open.c
@@ -0,0 +1,46 @@
+/*!A cross-platform build utility based on Lua
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Copyright (C) 2015-present, TBOOX Open Source Group.
+ *
+ * @author ruki
+ * @file decompress_stream_open.c
+ *
+ */
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * trace
+ */
+#define TB_TRACE_MODULE_NAME "decompress_stream_open"
+#define TB_TRACE_MODULE_DEBUG (0)
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * includes
+ */
+#include "prefix.h"
+
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * implementation
+ */
+tb_int_t xm_lz4_decompress_stream_open(lua_State* lua)
+{
+ // check
+ tb_assert_and_check_return_val(lua, 0);
+
+ xm_lz4_dstream_t* stream = xm_lz4_dstream_init();
+ if (stream) xm_lua_pushpointer(lua, (tb_pointer_t)stream);
+ lua_pushnil(lua);
+ return 1;
+}
+
diff --git a/core/src/xmake/makefile b/core/src/xmake/makefile
index 06b188fc9..597f3de3b 100644
--- a/core/src/xmake/makefile
+++ b/core/src/xmake/makefile
@@ -139,7 +139,11 @@ xmake_C_FILES += \
lz4/block_compress \
lz4/block_decompress \
lz4/compress_file \
- lz4/decompress_file
+ lz4/compress_stream_open \
+ lz4/compress_stream_close \
+ lz4/decompress_file \
+ lz4/decompress_stream_open \
+ lz4/decompress_stream_close
iswin =
ifeq ($(PLAT),windows)