| 313 | } |
| 314 | |
| 315 | napi_value hashAPI(napi_env env, napi_callback_info info) { |
| 316 | size_t argc = 2; |
| 317 | napi_value args[2]; |
| 318 | napi_get_cb_info(env, info, &argc, args, NULL, NULL); |
| 319 | |
| 320 | // Get buffer info for data (zero-copy) |
| 321 | void *buffer_data; |
| 322 | size_t buffer_length; |
| 323 | napi_status status = napi_get_buffer_info(env, args[0], &buffer_data, &buffer_length); |
| 324 | if (status != napi_ok) { |
| 325 | napi_throw_error(env, NULL, "First argument must be a Buffer"); |
| 326 | return NULL; |
| 327 | } |
| 328 | |
| 329 | // Get optional seed parameter (default to 0) |
| 330 | sz_u64_t seed = 0; |
| 331 | if (argc > 1) { |
| 332 | bool lossless; |
| 333 | napi_get_value_bigint_uint64(env, args[1], &seed, &lossless); |
| 334 | if (!lossless) { |
| 335 | // Try regular number if BigInt fails |
| 336 | double seed_double; |
| 337 | if (napi_get_value_double(env, args[1], &seed_double) == napi_ok) { seed = (sz_u64_t)seed_double; } |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | // Compute hash using StringZilla |
| 342 | sz_u64_t hash_result = sz_hash((sz_cptr_t)buffer_data, buffer_length, seed); |
| 343 | |
| 344 | // Convert result to JavaScript BigInt |
| 345 | napi_value js_result; |
| 346 | napi_create_bigint_uint64(env, hash_result, &js_result); |
| 347 | |
| 348 | return js_result; |
| 349 | } |
| 350 | |
| 351 | static void hasher_cleanup(napi_env env, void *data, void *hint) { free(data); } |
| 352 | typedef struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…