Skip to content

Commit 9a9b7c6

Browse files
committed
fixup! crypto_acompress
1 parent e06abd3 commit 9a9b7c6

File tree

1 file changed

+58
-9
lines changed

1 file changed

+58
-9
lines changed

lib/luacrypto_acompress.c

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,32 @@ static int luacrypto_acomp_req_##name(lua_State *L) \
213213
return 0; \
214214
}
215215

216+
/***
217+
* Request object methods.
218+
* These methods are available on request objects created by `ACOMPRESS:request()`.
219+
* @type crypto_acomp_req
220+
*/
221+
222+
/***
223+
* Compresses data asynchronously using the ACOMPRESS transform.
224+
* The callback is invoked when the operation completes (either synchronously or asynchronously).
225+
* @function compress
226+
* @tparam string data The data to compress.
227+
* @tparam integer output_size The maximum size of the output buffer.
228+
* @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).
229+
* @raise Error if the request object is busy, or if parameters are invalid.
230+
*/
216231
LUACRYPTO_ACOMP_REQ_OPERATION(compress)
232+
233+
/***
234+
* Decompresses data asynchronously using the ACOMPRESS transform.
235+
* The callback is invoked when the operation completes (either synchronously or asynchronously).
236+
* @function decompress
237+
* @tparam string data The compressed data to decompress.
238+
* @tparam integer output_size The maximum size of the output buffer.
239+
* @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).
240+
* @raise Error if the request object is busy, or if parameters are invalid.
241+
*/
217242
LUACRYPTO_ACOMP_REQ_OPERATION(decompress)
218243

219244
static const luaL_Reg luacrypto_acomp_req_mt[] = {
@@ -232,8 +257,21 @@ static const lunatik_class_t luacrypto_acomp_req_class = {
232257
.sleep = true,
233258
};
234259

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

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

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

272320
static const luaL_Reg luacrypto_acompress_lib[] = {
273321
{"new", luacrypto_acompress_new},
274322
{NULL, NULL}
275323
};
276324

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);
325+
static const lunatik_class_t luacrypto_acompress_classes[] = {
326+
luacrypto_acompress_class,
327+
luacrypto_acomp_req_class,
328+
{NULL}
329+
};
330+
331+
LUNATIK_NEWLIB_MULTICLASS(crypto_acompress, luacrypto_acompress_lib, luacrypto_acompress_classes, NULL);
283332

284333
static int __init luacrypto_acompress_init(void)
285334
{

0 commit comments

Comments
 (0)