2
0
ruki 2 сар өмнө
parent
commit
842f760e82

+ 169 - 36
docs/api/scripts/extension-modules/core/compress/lz4.md

@@ -13,12 +13,27 @@ To use this module, you need to import it first: `import("core.compress.lz4")`
 
 - Compress data (frame format)
 
-```lua
-import("core.compress.lz4")
+#### Function Prototype
 
-local compressed = lz4.compress("hello world")
-local compressed = lz4.compress(bytes_data)
+::: tip API
+```lua
+lz4.compress(data: <string|bytes>)
 ```
+:::
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| data | Required. Data to compress, can be a string or bytes object |
+
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| bytes | Compressed data (bytes object) |
+
+#### Usage
 
 Compresses data using the LZ4 frame format. Supports string or bytes object as input and returns a compressed bytes object.
 
@@ -27,22 +42,41 @@ The frame format contains complete metadata and is self-contained, recommended f
 ```lua
 import("core.compress.lz4")
 
--- Compress text data
-local data = "hello world"
-local compressed = lz4.compress(data)
-print("Original size:", #data)
+-- Compress string
+local compressed = lz4.compress("hello world")
+print("Original size: 11")
 print("Compressed size:", compressed:size())
+
+-- Can also compress bytes object
+local bytes_data = bytes("hello world")
+local compressed = lz4.compress(bytes_data)
 ```
 
 ## lz4.decompress
 
 - Decompress data (frame format)
 
-```lua
-import("core.compress.lz4")
+#### Function Prototype
 
-local decompressed = lz4.decompress(compressed_data)
+::: tip API
+```lua
+lz4.decompress(compressed: <bytes>)
 ```
+:::
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| compressed | Required. Data compressed using LZ4 frame format (bytes object) |
+
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| bytes | Decompressed data (bytes object) |
+
+#### Usage
 
 Decompresses data compressed using the LZ4 frame format and returns a decompressed bytes object.
 
@@ -61,26 +95,69 @@ assert(decompressed:str() == original)
 
 - Compress data (block format)
 
-```lua
-import("core.compress.lz4")
+#### Function Prototype
 
-local compressed = lz4.block_compress("hello world")
-local compressed = lz4.block_compress(bytes_data)
+::: tip API
+```lua
+lz4.block_compress(data: <string|bytes>)
 ```
+:::
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| data | Required. Data to compress, can be a string or bytes object |
+
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| bytes | Compressed data (bytes object) |
+
+#### Usage
 
 Compresses data using the LZ4 block format. The block format is more lightweight, does not include frame header information, resulting in smaller compressed data, but requires managing and recording the original data size information yourself.
 
 Suitable for scenarios with higher compression ratio requirements where you can manage metadata yourself.
 
+```lua
+import("core.compress.lz4")
+
+-- Compress string
+local compressed = lz4.block_compress("hello world")
+
+-- Or compress bytes object
+local bytes_data = bytes("hello world")
+local compressed = lz4.block_compress(bytes_data)
+```
+
 ## lz4.block_decompress
 
 - Decompress data (block format)
 
-```lua
-import("core.compress.lz4")
+#### Function Prototype
 
-local decompressed = lz4.block_decompress(compressed_data, realsize)
+::: tip API
+```lua
+lz4.block_decompress(compressed: <bytes>, realsize: <number>)
 ```
+:::
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| compressed | Required. Data compressed using LZ4 block format (bytes object) |
+| realsize | Required. Size of the original data |
+
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| bytes | Decompressed data (bytes object) |
+
+#### Usage
 
 Decompresses data compressed using the LZ4 block format. The original data size `realsize` must be provided.
 
@@ -104,17 +181,34 @@ assert(decompressed:str() == original)
 
 - Compress a file
 
-```lua
-import("core.compress.lz4")
+#### Function Prototype
 
-lz4.compress_file("input.txt", "output.lz4")
+::: tip API
+```lua
+lz4.compress_file(srcfile: <string>, dstfile: <string>)
 ```
+:::
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| srcfile | Required. Path to the source file to compress |
+| dstfile | Required. Path to the compressed destination file |
+
+#### Return Value
+
+This function has no return value.
+
+#### Usage
 
 Directly compresses a file using the LZ4 frame format. Compared to reading the entire file content and then compressing, this interface is more suitable for handling large files with lower memory usage:
 
 ```lua
 import("core.compress.lz4")
 
+lz4.compress_file("input.txt", "output.lz4")
+
 -- Compress build output
 local srcfile = "build/output.log"
 local dstfile = "build/output.log.lz4"
@@ -126,17 +220,34 @@ print("File compressed:", dstfile)
 
 - Decompress a file
 
-```lua
-import("core.compress.lz4")
+#### Function Prototype
 
-lz4.decompress_file("input.lz4", "output.txt")
+::: tip API
+```lua
+lz4.decompress_file(srcfile: <string>, dstfile: <string>)
 ```
+:::
+
+#### Parameter Description
+
+| Parameter | Description |
+|-----------|-------------|
+| srcfile | Required. Path to the source file to decompress |
+| dstfile | Required. Path to the decompressed destination file |
+
+#### Return Value
+
+This function has no return value.
+
+#### Usage
 
 Directly decompresses a file and restores the original file content:
 
 ```lua
 import("core.compress.lz4")
 
+lz4.decompress_file("input.lz4", "output.txt")
+
 -- Decompress log file
 local srcfile = "build/output.log.lz4"
 local dstfile = "build/output.log"
@@ -151,16 +262,27 @@ print(content)
 
 - Open a compression stream
 
-```lua
-import("core.compress.lz4")
+#### Function Prototype
 
-local stream = lz4.compress_stream()
+::: tip API
+```lua
+lz4.compress_stream()
 ```
+:::
+
+#### Parameter Description
+
+No parameters required for this function.
 
-Creates a compression stream object for streaming data compression. The compression stream supports the following methods:
+#### Return Value
 
-- `stream:write(data, opt)` - Write data for compression
-- `stream:read(buffer, size, opt)` - Read compressed data
+| Type | Description |
+|------|-------------|
+| stream | Compression stream object supporting the following methods:<br>- `stream:write(data, opt)` - Write data for compression<br>- `stream:read(buffer, size, opt)` - Read compressed data |
+
+#### Usage
+
+Creates a compression stream object for streaming data compression.
 
 Streaming compression is suitable for the following scenarios:
 - Handling large files, compressing while reading, without loading all content at once
@@ -190,16 +312,27 @@ end
 
 - Open a decompression stream
 
-```lua
-import("core.compress.lz4")
+#### Function Prototype
 
-local stream = lz4.decompress_stream()
+::: tip API
+```lua
+lz4.decompress_stream()
 ```
+:::
+
+#### Parameter Description
+
+No parameters required for this function.
+
+#### Return Value
+
+| Type | Description |
+|------|-------------|
+| stream | Decompression stream object supporting the following methods:<br>- `stream:write(data, opt)` - Write compressed data<br>- `stream:read(buffer, size, opt)` - Read decompressed data |
 
-Creates a decompression stream object for streaming data decompression. The decompression stream supports the following methods:
+#### Usage
 
-- `stream:write(data, opt)` - Write compressed data
-- `stream:read(buffer, size, opt)` - Read decompressed data
+Creates a decompression stream object for streaming data decompression.
 
 Streaming decompression example:
 

+ 169 - 36
docs/zh/api/scripts/extension-modules/core/compress/lz4.md

@@ -13,12 +13,27 @@ LZ4 是一个非常快速的无损压缩算法,专注于压缩和解压速度
 
 - 压缩数据(帧格式)
 
-```lua
-import("core.compress.lz4")
+#### 函数原型
 
-local compressed = lz4.compress("hello world")
-local compressed = lz4.compress(bytes_data)
+::: tip API
+```lua
+lz4.compress(data: <string|bytes>)
 ```
+:::
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| data | 必需。要压缩的数据,可以是字符串或 bytes 对象 |
+
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| bytes | 压缩后的数据(bytes 对象) |
+
+#### 用法说明
 
 使用 LZ4 帧格式压缩数据,支持字符串或 bytes 对象作为输入,返回压缩后的 bytes 对象。
 
@@ -27,22 +42,41 @@ local compressed = lz4.compress(bytes_data)
 ```lua
 import("core.compress.lz4")
 
--- 压缩文本数据
-local data = "hello world"
-local compressed = lz4.compress(data)
-print("原始大小:", #data)
+-- 压缩字符串
+local compressed = lz4.compress("hello world")
+print("原始大小: 11")
 print("压缩后大小:", compressed:size())
+
+-- 也可以压缩 bytes 对象
+local bytes_data = bytes("hello world")
+local compressed = lz4.compress(bytes_data)
 ```
 
 ## lz4.decompress
 
 - 解压数据(帧格式)
 
-```lua
-import("core.compress.lz4")
+#### 函数原型
 
-local decompressed = lz4.decompress(compressed_data)
+::: tip API
+```lua
+lz4.decompress(compressed: <bytes>)
 ```
+:::
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| compressed | 必需。使用 LZ4 帧格式压缩的数据(bytes 对象) |
+
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| bytes | 解压后的数据(bytes 对象) |
+
+#### 用法说明
 
 解压使用 LZ4 帧格式压缩的数据,返回解压后的 bytes 对象。
 
@@ -61,26 +95,69 @@ assert(decompressed:str() == original)
 
 - 压缩数据(块格式)
 
-```lua
-import("core.compress.lz4")
+#### 函数原型
 
-local compressed = lz4.block_compress("hello world")
-local compressed = lz4.block_compress(bytes_data)
+::: tip API
+```lua
+lz4.block_compress(data: <string|bytes>)
 ```
+:::
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| data | 必需。要压缩的数据,可以是字符串或 bytes 对象 |
+
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| bytes | 压缩后的数据(bytes 对象) |
+
+#### 用法说明
 
 使用 LZ4 块格式压缩数据。块格式更轻量,不包含帧头信息,压缩后的数据更小,但需要自行管理和记录原始数据大小信息。
 
 适合对压缩率要求较高,且可以自行管理元数据的场景。
 
+```lua
+import("core.compress.lz4")
+
+-- 压缩字符串
+local compressed = lz4.block_compress("hello world")
+
+-- 或压缩 bytes 对象
+local bytes_data = bytes("hello world")
+local compressed = lz4.block_compress(bytes_data)
+```
+
 ## lz4.block_decompress
 
 - 解压数据(块格式)
 
-```lua
-import("core.compress.lz4")
+#### 函数原型
 
-local decompressed = lz4.block_decompress(compressed_data, realsize)
+::: tip API
+```lua
+lz4.block_decompress(compressed: <bytes>, realsize: <number>)
 ```
+:::
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| compressed | 必需。使用 LZ4 块格式压缩的数据(bytes 对象) |
+| realsize | 必需。原始数据的大小 |
+
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| bytes | 解压后的数据(bytes 对象) |
+
+#### 用法说明
 
 解压使用 LZ4 块格式压缩的数据,必须提供原始数据的大小 `realsize`。
 
@@ -104,17 +181,34 @@ assert(decompressed:str() == original)
 
 - 压缩文件
 
-```lua
-import("core.compress.lz4")
+#### 函数原型
 
-lz4.compress_file("input.txt", "output.lz4")
+::: tip API
+```lua
+lz4.compress_file(srcfile: <string>, dstfile: <string>)
 ```
+:::
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| srcfile | 必需。要压缩的源文件路径 |
+| dstfile | 必需。压缩后的目标文件路径 |
+
+#### 返回值说明
+
+此函数无返回值。
+
+#### 用法说明
 
 直接压缩文件,使用 LZ4 帧格式。相比一次性读取整个文件内容再压缩,这个接口更适合处理大文件,内存占用更低:
 
 ```lua
 import("core.compress.lz4")
 
+lz4.compress_file("input.txt", "output.lz4")
+
 -- 压缩构建输出
 local srcfile = "build/output.log"
 local dstfile = "build/output.log.lz4"
@@ -126,17 +220,34 @@ print("文件已压缩:", dstfile)
 
 - 解压文件
 
-```lua
-import("core.compress.lz4")
+#### 函数原型
 
-lz4.decompress_file("input.lz4", "output.txt")
+::: tip API
+```lua
+lz4.decompress_file(srcfile: <string>, dstfile: <string>)
 ```
+:::
+
+#### 参数说明
+
+| 参数 | 描述 |
+|------|------|
+| srcfile | 必需。要解压的源文件路径 |
+| dstfile | 必需。解压后的目标文件路径 |
+
+#### 返回值说明
+
+此函数无返回值。
+
+#### 用法说明
 
 直接解压文件,恢复原始文件内容:
 
 ```lua
 import("core.compress.lz4")
 
+lz4.decompress_file("input.lz4", "output.txt")
+
 -- 解压日志文件
 local srcfile = "build/output.log.lz4"
 local dstfile = "build/output.log"
@@ -151,16 +262,27 @@ print(content)
 
 - 打开压缩流
 
-```lua
-import("core.compress.lz4")
+#### 函数原型
 
-local stream = lz4.compress_stream()
+::: tip API
+```lua
+lz4.compress_stream()
 ```
+:::
+
+#### 参数说明
+
+此函数不需要参数。
 
-创建一个压缩流对象,用于流式压缩数据。压缩流支持以下方法:
+#### 返回值说明
 
-- `stream:write(data, opt)` - 写入数据进行压缩
-- `stream:read(buffer, size, opt)` - 读取压缩后的数据
+| 类型 | 描述 |
+|------|------|
+| stream | 压缩流对象,支持以下方法:<br>- `stream:write(data, opt)` - 写入数据进行压缩<br>- `stream:read(buffer, size, opt)` - 读取压缩后的数据 |
+
+#### 用法说明
+
+创建一个压缩流对象,用于流式压缩数据。
 
 流式压缩适合以下场景:
 - 处理大文件,边读边压缩,不需要一次性加载全部内容
@@ -190,16 +312,27 @@ end
 
 - 打开解压流
 
-```lua
-import("core.compress.lz4")
+#### 函数原型
 
-local stream = lz4.decompress_stream()
+::: tip API
+```lua
+lz4.decompress_stream()
 ```
+:::
+
+#### 参数说明
+
+此函数不需要参数。
+
+#### 返回值说明
+
+| 类型 | 描述 |
+|------|------|
+| stream | 解压流对象,支持以下方法:<br>- `stream:write(data, opt)` - 写入压缩数据<br>- `stream:read(buffer, size, opt)` - 读取解压后的数据 |
 
-创建一个解压流对象,用于流式解压数据。解压流支持以下方法:
+#### 用法说明
 
-- `stream:write(data, opt)` - 写入压缩数据
-- `stream:read(buffer, size, opt)` - 读取解压后的数据
+创建一个解压流对象,用于流式解压数据。
 
 流式解压示例: