Skip to content

Commit 59c56ec

Browse files
committed
fixup! crypto_acompress
1 parent a1e8d92 commit 59c56ec

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

lib/luacrypto_acompress.c

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <lua.h>
2929
#include <lualib.h>
3030
#include <lauxlib.h>
31+
3132
#include <lunatik.h>
3233

3334
#include "luacrypto.h"
@@ -213,7 +214,32 @@ static int luacrypto_acomp_req_##name(lua_State *L) \
213214
return 0; \
214215
}
215216

217+
/***
218+
* Request object methods.
219+
* These methods are available on request objects created by `ACOMPRESS:request()`.
220+
* @type crypto_acomp_req
221+
*/
222+
223+
/***
224+
* Compresses data asynchronously using the ACOMPRESS transform.
225+
* The callback is invoked when the operation completes (either synchronously or asynchronously).
226+
* @function compress
227+
* @tparam string data The data to compress.
228+
* @tparam integer output_size The maximum size of the output buffer.
229+
* @tparam function callback The callback function to invoke upon completion. It receives two arguments: `err` (integer error code, 0 on success) and `data` (string containing compressed data, or nil on error).
230+
* @raise Error if the request object is busy, or if parameters are invalid.
231+
*/
216232
LUACRYPTO_ACOMP_REQ_OPERATION(compress)
233+
234+
/***
235+
* Decompresses data asynchronously using the ACOMPRESS transform.
236+
* The callback is invoked when the operation completes (either synchronously or asynchronously).
237+
* @function decompress
238+
* @tparam string data The compressed data to decompress.
239+
* @tparam integer output_size The maximum size of the output buffer.
240+
* @tparam function callback The callback function to invoke upon completion. It receives two arguments: `err` (integer error code, 0 on success) and `data` (string containing decompressed data, or nil on error).
241+
* @raise Error if the request object is busy, or if parameters are invalid.
242+
*/
217243
LUACRYPTO_ACOMP_REQ_OPERATION(decompress)
218244

219245
static const luaL_Reg luacrypto_acomp_req_mt[] = {
@@ -232,8 +258,21 @@ static const lunatik_class_t luacrypto_acomp_req_class = {
232258
.sleep = true,
233259
};
234260

235-
/* ACOMPRESS TFM Methods */
261+
/***
262+
* ACOMPRESS object methods.
263+
* These methods are available on ACOMPRESS TFM objects created by `crypto.acompress.new()`.
264+
* @see new
265+
* @type ACOMPRESS
266+
*/
236267

268+
/***
269+
* Creates a new asynchronous compression request object.
270+
* Request objects are used to perform asynchronous compression and decompression operations.
271+
* Multiple requests can be created from the same TFM and used concurrently.
272+
* @function request
273+
* @treturn crypto_acomp_req A new request object.
274+
* @raise Error if request allocation fails.
275+
*/
237276
static int luacrypto_acompress_request(lua_State *L)
238277
{
239278
struct crypto_acomp *tfm = luacrypto_acompress_check(L, 1);
@@ -265,21 +304,32 @@ static const luaL_Reg luacrypto_acompress_mt[] = {
265304
{NULL, NULL}
266305
};
267306

268-
/* Module Init */
269-
307+
/***
308+
* Creates a new ACOMPRESS transform object for the specified algorithm.
309+
* @function new
310+
* @tparam string algorithm The name of the compression algorithm (e.g., "lz4", "deflate", "lzo").
311+
* @treturn ACOMPRESS A new ACOMPRESS transform object.
312+
* @raise Error if the algorithm is not found or allocation fails.
313+
* @usage
314+
* local acomp = require("crypto.acompress")
315+
* local tfm = acomp.new("lz4")
316+
* local req = tfm:request()
317+
* @within crypto_acompress
318+
*/
270319
LUACRYPTO_NEW(acompress, struct crypto_acomp, crypto_alloc_acomp, luacrypto_acompress_class, NULL);
271320

272321
static const luaL_Reg luacrypto_acompress_lib[] = {
273322
{"new", luacrypto_acompress_new},
274323
{NULL, NULL}
275324
};
276325

277-
LUNATIK_NEWLIB_MULTICLASS(crypto_acompress, luacrypto_acompress_lib,
278-
((const lunatik_class_t[]){
279-
luacrypto_acompress_class,
280-
luacrypto_acomp_req_class,
281-
{NULL}
282-
}), NULL);
326+
static const lunatik_class_t luacrypto_acompress_classes[] = {
327+
luacrypto_acompress_class,
328+
luacrypto_acomp_req_class,
329+
{NULL}
330+
};
331+
332+
LUNATIK_NEWLIB_MULTICLASS(crypto_acompress, luacrypto_acompress_lib, luacrypto_acompress_classes, NULL);
283333

284334
static int __init luacrypto_acompress_init(void)
285335
{

0 commit comments

Comments
 (0)