zeck 1.0.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/package.json +2 -3
- package/zeck.d.ts +87 -49
- package/zeck_bg.js +100 -62
- package/zeck_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -408,6 +408,28 @@ This avoids redundant Fibonacci numbers (F(0)=0 and F(1)=F(2)=1).
|
|
|
408
408
|
- The library supports both big-endian and little-endian interpretations, but other byte orderings or word boundaries are not currently explored
|
|
409
409
|
- **⚠️ Warning:** Compressing or decompressing files larger than 10KB (10,000 bytes) is unstable due to time and memory pressure. The library may experience performance issues, excessive memory usage, or failures when processing files exceeding this size.
|
|
410
410
|
|
|
411
|
+
## NPM Versioning Quirk
|
|
412
|
+
|
|
413
|
+
For some reason, NPM was showing there were versions of zeck published between `1.0.0` and `1.0.6` from 2024, even though I never published them to npm. I don't know how this happened. So I bumped the version to `1.0.7` and was able to successfully publish it to npm. Maybe there was an old package with the same name that was deleted, and NPM is still showing the old versions.
|
|
414
|
+
|
|
415
|
+
Here is a snippet of the `time` object from the npm registry JSON (https://registry.npmjs.org/zeck):
|
|
416
|
+
|
|
417
|
+
```json
|
|
418
|
+
"time": {
|
|
419
|
+
"created": "2026-01-02T20:19:14.018Z",
|
|
420
|
+
"modified": "2026-01-03T17:25:15.940Z",
|
|
421
|
+
"1.0.0": "2024-02-21T14:36:36.292Z",
|
|
422
|
+
"1.0.1": "2024-02-21T15:26:38.621Z",
|
|
423
|
+
"1.0.2": "2024-02-21T15:36:30.258Z",
|
|
424
|
+
"1.0.3": "2024-02-21T15:48:07.853Z",
|
|
425
|
+
"1.0.4": "2024-02-21T15:48:38.804Z",
|
|
426
|
+
"1.0.5": "2024-02-21T16:02:36.339Z",
|
|
427
|
+
"1.0.6": "2024-02-21T16:36:36.643Z",
|
|
428
|
+
"0.1.0": "2026-01-02T20:19:14.175Z",
|
|
429
|
+
"0.2.0": "2026-01-03T17:25:15.702Z"
|
|
430
|
+
},
|
|
431
|
+
```
|
|
432
|
+
|
|
411
433
|
## License
|
|
412
434
|
|
|
413
435
|
This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"Peter Ryszkiewicz"
|
|
6
6
|
],
|
|
7
7
|
"description": "A Rust library for compressing and decompressing data using the Zeckendorf representation algorithm",
|
|
8
|
-
"version": "
|
|
8
|
+
"version": "2.0.0",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
"zeck_bg.wasm",
|
|
16
16
|
"zeck.js",
|
|
17
17
|
"zeck_bg.js",
|
|
18
|
-
"zeck.d.ts"
|
|
19
|
-
"LICENSE.txt"
|
|
18
|
+
"zeck.d.ts"
|
|
20
19
|
],
|
|
21
20
|
"main": "zeck.js",
|
|
22
21
|
"types": "zeck.d.ts",
|
package/zeck.d.ts
CHANGED
|
@@ -236,24 +236,20 @@ export function memoized_zeckendorf_list_descending_for_integer(n: bigint): BigU
|
|
|
236
236
|
export function pack_ezba_bits_to_bytes(ezba: Uint8Array): Uint8Array;
|
|
237
237
|
|
|
238
238
|
/**
|
|
239
|
-
*
|
|
239
|
+
* Compresses a slice of bytes using the Padless Zeckendorf Compression algorithm.
|
|
240
240
|
*
|
|
241
|
-
*
|
|
241
|
+
* Assumes the input data is interpreted as a big endian integer. The output data is in little endian order, so the first bit and byte is the least significant bit and byte and the last bit and byte is the most significant bit and byte.
|
|
242
242
|
*
|
|
243
|
-
*
|
|
244
|
-
* # use zeck::unpack_bytes_to_ezba_bits;
|
|
245
|
-
* assert_eq!(unpack_bytes_to_ezba_bits(&[0]), vec![0, 0, 0, 0, 0, 0, 0, 0]);
|
|
246
|
-
* assert_eq!(unpack_bytes_to_ezba_bits(&[1]), vec![1, 0, 0, 0, 0, 0, 0, 0]);
|
|
247
|
-
* assert_eq!(unpack_bytes_to_ezba_bits(&[0b111]), vec![1, 1, 1, 0, 0, 0, 0, 0]);
|
|
248
|
-
* assert_eq!(unpack_bytes_to_ezba_bits(&[1, 1]), vec![1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]);
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
export function unpack_bytes_to_ezba_bits(bytes: Uint8Array): Uint8Array;
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Compresses a slice of bytes using the Zeckendorf algorithm.
|
|
243
|
+
* # ⚠️ Important: Original Size Preservation
|
|
255
244
|
*
|
|
256
|
-
*
|
|
245
|
+
* **This function strips leading zero bytes from the input data during compression.**
|
|
246
|
+
* It is the caller's responsibility to retain the original size information (e.g., `data.len()`)
|
|
247
|
+
* before calling this function. When decompressing, the original size must be used to pad the
|
|
248
|
+
* decompressed data with leading zeros to restore the exact original data. Without the original
|
|
249
|
+
* size, information will be lost during decompression.
|
|
250
|
+
*
|
|
251
|
+
* For a format that automatically handles size preservation, use [`crate::zeck_file_format::compress::compress_zeck_be`]
|
|
252
|
+
* instead, which includes a header with the original size information.
|
|
257
253
|
*
|
|
258
254
|
* # ⚠️ Warning
|
|
259
255
|
*
|
|
@@ -265,23 +261,34 @@ export function unpack_bytes_to_ezba_bits(bytes: Uint8Array): Uint8Array;
|
|
|
265
261
|
* # Examples
|
|
266
262
|
*
|
|
267
263
|
* ```
|
|
268
|
-
* # use zeck::
|
|
269
|
-
* assert_eq!(
|
|
270
|
-
* assert_eq!(
|
|
271
|
-
* assert_eq!(
|
|
272
|
-
* assert_eq!(
|
|
273
|
-
* assert_eq!(
|
|
274
|
-
* assert_eq!(
|
|
275
|
-
* assert_eq!(
|
|
264
|
+
* # use zeck::padless_zeckendorf_compress_be_dangerous;
|
|
265
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[0]), vec![0]);
|
|
266
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[1]), vec![1]);
|
|
267
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[12]), vec![0b111]);
|
|
268
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[54]), vec![30]);
|
|
269
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[55]), vec![0, 1]); // 55 is the 10 indexed Fibonacci number, which is the 8 indexed effective Fibonacci number, and therefore is the first number needing two bytes to contain these 8 bits, because there is 1 "use bit" and 7 "skip bits" in the effective zeckendorf bits ascending.
|
|
270
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[255]), vec![33, 2]);
|
|
271
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[1, 0]), vec![34, 2]);
|
|
276
272
|
* ```
|
|
277
273
|
*/
|
|
278
|
-
export function
|
|
274
|
+
export function padless_zeckendorf_compress_be_dangerous(data: Uint8Array): Uint8Array;
|
|
279
275
|
|
|
280
276
|
/**
|
|
281
|
-
* Compresses a slice of bytes using the Zeckendorf algorithm.
|
|
277
|
+
* Compresses a slice of bytes using the Padless Zeckendorf Compression algorithm.
|
|
282
278
|
*
|
|
283
279
|
* Assumes the input data is interpreted as a little endian integer. The output data is in little endian order, so the first bit and byte is the least significant bit and byte and the last bit and byte is the most significant bit and byte.
|
|
284
280
|
*
|
|
281
|
+
* # ⚠️ Important: Original Size Preservation
|
|
282
|
+
*
|
|
283
|
+
* **This function strips leading zero bytes from the input data during compression.**
|
|
284
|
+
* It is the caller's responsibility to retain the original size information (e.g., `data.len()`)
|
|
285
|
+
* before calling this function. When decompressing, the original size must be used to pad the
|
|
286
|
+
* decompressed data with leading zeros to restore the exact original data. Without the original
|
|
287
|
+
* size, information will be lost during decompression.
|
|
288
|
+
*
|
|
289
|
+
* For a format that automatically handles size preservation, use [`crate::zeck_file_format::compress::compress_zeck_le`]
|
|
290
|
+
* instead, which includes a header with the original size information.
|
|
291
|
+
*
|
|
285
292
|
* # ⚠️ Warning
|
|
286
293
|
*
|
|
287
294
|
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
@@ -290,22 +297,30 @@ export function zeckendorf_compress_be_broken_do_not_use(data: Uint8Array): Uint
|
|
|
290
297
|
* # Examples
|
|
291
298
|
*
|
|
292
299
|
* ```
|
|
293
|
-
* # use zeck::
|
|
294
|
-
* assert_eq!(
|
|
295
|
-
* assert_eq!(
|
|
296
|
-
* assert_eq!(
|
|
297
|
-
* assert_eq!(
|
|
298
|
-
* assert_eq!(
|
|
299
|
-
* assert_eq!(
|
|
300
|
-
* assert_eq!(
|
|
300
|
+
* # use zeck::padless_zeckendorf_compress_le_dangerous;
|
|
301
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[0]), vec![0]);
|
|
302
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[1]), vec![1]);
|
|
303
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[12]), vec![0b111]);
|
|
304
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[54]), vec![30]);
|
|
305
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[55]), vec![0, 1]); // 55 is the 10 indexed Fibonacci number, which is the 8 indexed effective Fibonacci number, and therefore is the first number needing two bytes to contain these 8 bits, because there is 1 "use bit" and 7 "skip bits" in the effective zeckendorf bits ascending.
|
|
306
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[255]), vec![33, 2]);
|
|
307
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[0, 1]), vec![34, 2]);
|
|
301
308
|
* ```
|
|
302
309
|
*/
|
|
303
|
-
export function
|
|
310
|
+
export function padless_zeckendorf_compress_le_dangerous(data: Uint8Array): Uint8Array;
|
|
304
311
|
|
|
305
312
|
/**
|
|
306
313
|
* Decompresses a slice of bytes compressed using the Zeckendorf algorithm, assuming the original data was compressed using the big endian bytes interpretation.
|
|
307
314
|
*
|
|
308
|
-
* Assume the original input data was interpreted as a big endian integer, for now. See the TODO in the [`
|
|
315
|
+
* Assume the original input data was interpreted as a big endian integer, for now. See the TODO in the [`padless_zeckendorf_compress_be_dangerous`] function for more information.
|
|
316
|
+
*
|
|
317
|
+
* # ⚠️ Important: Leading Zero Padding
|
|
318
|
+
*
|
|
319
|
+
* **This function does not pad leading zero bytes.** If the original data had leading zeros, they will not be restored.
|
|
320
|
+
* The decompressed output will be the minimal representation of the number (without leading zeros).
|
|
321
|
+
*
|
|
322
|
+
* For a format that automatically handles size preservation and padding, use [`crate::zeck_file_format::file::deserialize_zeck_file`]
|
|
323
|
+
* and [`crate::zeck_file_format::decompress::decompress_zeck_file`] instead, which includes a header with the original size information and restores leading zeros.
|
|
309
324
|
*
|
|
310
325
|
* # ⚠️ Warning
|
|
311
326
|
*
|
|
@@ -315,19 +330,27 @@ export function zeckendorf_compress_le_broken_do_not_use(data: Uint8Array): Uint
|
|
|
315
330
|
* # Examples
|
|
316
331
|
*
|
|
317
332
|
* ```
|
|
318
|
-
* # use zeck::
|
|
319
|
-
* assert_eq!(
|
|
320
|
-
* assert_eq!(
|
|
321
|
-
* assert_eq!(
|
|
322
|
-
* assert_eq!(
|
|
323
|
-
* assert_eq!(
|
|
333
|
+
* # use zeck::padless_zeckendorf_decompress_be_dangerous;
|
|
334
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[0]), vec![0]);
|
|
335
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[1]), vec![1]);
|
|
336
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[0b111]), vec![12]);
|
|
337
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[33, 2]), vec![255]);
|
|
338
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[34, 2]), vec![1, 0]);
|
|
324
339
|
* ```
|
|
325
340
|
*/
|
|
326
|
-
export function
|
|
341
|
+
export function padless_zeckendorf_decompress_be_dangerous(compressed_data: Uint8Array): Uint8Array;
|
|
327
342
|
|
|
328
343
|
/**
|
|
329
344
|
* Decompresses a slice of bytes compressed using the Zeckendorf algorithm, assuming the original data was compressed using the little endian bytes interpretation.
|
|
330
345
|
*
|
|
346
|
+
* # ⚠️ Important: Leading Zero Padding
|
|
347
|
+
*
|
|
348
|
+
* **This function does not pad leading zero bytes.** If the original data had leading zeros, they will not be restored.
|
|
349
|
+
* The decompressed output will be the minimal representation of the number (without leading zeros).
|
|
350
|
+
*
|
|
351
|
+
* For a format that automatically handles size preservation and padding, use [`crate::zeck_file_format::file::deserialize_zeck_file`]
|
|
352
|
+
* and [`crate::zeck_file_format::decompress::decompress_zeck_file`] instead, which includes a header with the original size information and restores leading zeros.
|
|
353
|
+
*
|
|
331
354
|
* # ⚠️ Warning
|
|
332
355
|
*
|
|
333
356
|
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
@@ -336,15 +359,30 @@ export function zeckendorf_decompress_be_broken_do_not_use(compressed_data: Uint
|
|
|
336
359
|
* # Examples
|
|
337
360
|
*
|
|
338
361
|
* ```
|
|
339
|
-
* # use zeck::
|
|
340
|
-
* assert_eq!(
|
|
341
|
-
* assert_eq!(
|
|
342
|
-
* assert_eq!(
|
|
343
|
-
* assert_eq!(
|
|
344
|
-
* assert_eq!(
|
|
362
|
+
* # use zeck::padless_zeckendorf_decompress_le_dangerous;
|
|
363
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[0]), vec![0]);
|
|
364
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[1]), vec![1]);
|
|
365
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[0b111]), vec![12]);
|
|
366
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[33, 2]), vec![255]);
|
|
367
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[34, 2]), vec![0, 1]);
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
export function padless_zeckendorf_decompress_le_dangerous(compressed_data: Uint8Array): Uint8Array;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Unpacks a vector of bytes into a vector of bits (0s and 1s) from an ezba (Effective Zeckendorf Bits Ascending).
|
|
374
|
+
*
|
|
375
|
+
* # Examples
|
|
376
|
+
*
|
|
377
|
+
* ```
|
|
378
|
+
* # use zeck::unpack_bytes_to_ezba_bits;
|
|
379
|
+
* assert_eq!(unpack_bytes_to_ezba_bits(&[0]), vec![0, 0, 0, 0, 0, 0, 0, 0]);
|
|
380
|
+
* assert_eq!(unpack_bytes_to_ezba_bits(&[1]), vec![1, 0, 0, 0, 0, 0, 0, 0]);
|
|
381
|
+
* assert_eq!(unpack_bytes_to_ezba_bits(&[0b111]), vec![1, 1, 1, 0, 0, 0, 0, 0]);
|
|
382
|
+
* assert_eq!(unpack_bytes_to_ezba_bits(&[1, 1]), vec![1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]);
|
|
345
383
|
* ```
|
|
346
384
|
*/
|
|
347
|
-
export function
|
|
385
|
+
export function unpack_bytes_to_ezba_bits(bytes: Uint8Array): Uint8Array;
|
|
348
386
|
|
|
349
387
|
/**
|
|
350
388
|
* An Effective Zeckendorf List (EZL) has a lowest EFI of 0, which is an FI of 2.
|
package/zeck_bg.js
CHANGED
|
@@ -353,33 +353,20 @@ export function pack_ezba_bits_to_bytes(ezba) {
|
|
|
353
353
|
}
|
|
354
354
|
|
|
355
355
|
/**
|
|
356
|
-
*
|
|
356
|
+
* Compresses a slice of bytes using the Padless Zeckendorf Compression algorithm.
|
|
357
357
|
*
|
|
358
|
-
*
|
|
358
|
+
* Assumes the input data is interpreted as a big endian integer. The output data is in little endian order, so the first bit and byte is the least significant bit and byte and the last bit and byte is the most significant bit and byte.
|
|
359
359
|
*
|
|
360
|
-
*
|
|
361
|
-
* # use zeck::unpack_bytes_to_ezba_bits;
|
|
362
|
-
* assert_eq!(unpack_bytes_to_ezba_bits(&[0]), vec![0, 0, 0, 0, 0, 0, 0, 0]);
|
|
363
|
-
* assert_eq!(unpack_bytes_to_ezba_bits(&[1]), vec![1, 0, 0, 0, 0, 0, 0, 0]);
|
|
364
|
-
* assert_eq!(unpack_bytes_to_ezba_bits(&[0b111]), vec![1, 1, 1, 0, 0, 0, 0, 0]);
|
|
365
|
-
* assert_eq!(unpack_bytes_to_ezba_bits(&[1, 1]), vec![1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]);
|
|
366
|
-
* ```
|
|
367
|
-
* @param {Uint8Array} bytes
|
|
368
|
-
* @returns {Uint8Array}
|
|
369
|
-
*/
|
|
370
|
-
export function unpack_bytes_to_ezba_bits(bytes) {
|
|
371
|
-
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
372
|
-
const len0 = WASM_VECTOR_LEN;
|
|
373
|
-
const ret = wasm.unpack_bytes_to_ezba_bits(ptr0, len0);
|
|
374
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
375
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
376
|
-
return v2;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Compresses a slice of bytes using the Zeckendorf algorithm.
|
|
360
|
+
* # ⚠️ Important: Original Size Preservation
|
|
381
361
|
*
|
|
382
|
-
*
|
|
362
|
+
* **This function strips leading zero bytes from the input data during compression.**
|
|
363
|
+
* It is the caller's responsibility to retain the original size information (e.g., `data.len()`)
|
|
364
|
+
* before calling this function. When decompressing, the original size must be used to pad the
|
|
365
|
+
* decompressed data with leading zeros to restore the exact original data. Without the original
|
|
366
|
+
* size, information will be lost during decompression.
|
|
367
|
+
*
|
|
368
|
+
* For a format that automatically handles size preservation, use [`crate::zeck_file_format::compress::compress_zeck_be`]
|
|
369
|
+
* instead, which includes a header with the original size information.
|
|
383
370
|
*
|
|
384
371
|
* # ⚠️ Warning
|
|
385
372
|
*
|
|
@@ -391,32 +378,43 @@ export function unpack_bytes_to_ezba_bits(bytes) {
|
|
|
391
378
|
* # Examples
|
|
392
379
|
*
|
|
393
380
|
* ```
|
|
394
|
-
* # use zeck::
|
|
395
|
-
* assert_eq!(
|
|
396
|
-
* assert_eq!(
|
|
397
|
-
* assert_eq!(
|
|
398
|
-
* assert_eq!(
|
|
399
|
-
* assert_eq!(
|
|
400
|
-
* assert_eq!(
|
|
401
|
-
* assert_eq!(
|
|
381
|
+
* # use zeck::padless_zeckendorf_compress_be_dangerous;
|
|
382
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[0]), vec![0]);
|
|
383
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[1]), vec![1]);
|
|
384
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[12]), vec![0b111]);
|
|
385
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[54]), vec![30]);
|
|
386
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[55]), vec![0, 1]); // 55 is the 10 indexed Fibonacci number, which is the 8 indexed effective Fibonacci number, and therefore is the first number needing two bytes to contain these 8 bits, because there is 1 "use bit" and 7 "skip bits" in the effective zeckendorf bits ascending.
|
|
387
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[255]), vec![33, 2]);
|
|
388
|
+
* assert_eq!(padless_zeckendorf_compress_be_dangerous(&[1, 0]), vec![34, 2]);
|
|
402
389
|
* ```
|
|
403
390
|
* @param {Uint8Array} data
|
|
404
391
|
* @returns {Uint8Array}
|
|
405
392
|
*/
|
|
406
|
-
export function
|
|
393
|
+
export function padless_zeckendorf_compress_be_dangerous(data) {
|
|
407
394
|
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
408
395
|
const len0 = WASM_VECTOR_LEN;
|
|
409
|
-
const ret = wasm.
|
|
396
|
+
const ret = wasm.padless_zeckendorf_compress_be_dangerous(ptr0, len0);
|
|
410
397
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
411
398
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
412
399
|
return v2;
|
|
413
400
|
}
|
|
414
401
|
|
|
415
402
|
/**
|
|
416
|
-
* Compresses a slice of bytes using the Zeckendorf algorithm.
|
|
403
|
+
* Compresses a slice of bytes using the Padless Zeckendorf Compression algorithm.
|
|
417
404
|
*
|
|
418
405
|
* Assumes the input data is interpreted as a little endian integer. The output data is in little endian order, so the first bit and byte is the least significant bit and byte and the last bit and byte is the most significant bit and byte.
|
|
419
406
|
*
|
|
407
|
+
* # ⚠️ Important: Original Size Preservation
|
|
408
|
+
*
|
|
409
|
+
* **This function strips leading zero bytes from the input data during compression.**
|
|
410
|
+
* It is the caller's responsibility to retain the original size information (e.g., `data.len()`)
|
|
411
|
+
* before calling this function. When decompressing, the original size must be used to pad the
|
|
412
|
+
* decompressed data with leading zeros to restore the exact original data. Without the original
|
|
413
|
+
* size, information will be lost during decompression.
|
|
414
|
+
*
|
|
415
|
+
* For a format that automatically handles size preservation, use [`crate::zeck_file_format::compress::compress_zeck_le`]
|
|
416
|
+
* instead, which includes a header with the original size information.
|
|
417
|
+
*
|
|
420
418
|
* # ⚠️ Warning
|
|
421
419
|
*
|
|
422
420
|
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
@@ -425,22 +423,22 @@ export function zeckendorf_compress_be_broken_do_not_use(data) {
|
|
|
425
423
|
* # Examples
|
|
426
424
|
*
|
|
427
425
|
* ```
|
|
428
|
-
* # use zeck::
|
|
429
|
-
* assert_eq!(
|
|
430
|
-
* assert_eq!(
|
|
431
|
-
* assert_eq!(
|
|
432
|
-
* assert_eq!(
|
|
433
|
-
* assert_eq!(
|
|
434
|
-
* assert_eq!(
|
|
435
|
-
* assert_eq!(
|
|
426
|
+
* # use zeck::padless_zeckendorf_compress_le_dangerous;
|
|
427
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[0]), vec![0]);
|
|
428
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[1]), vec![1]);
|
|
429
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[12]), vec![0b111]);
|
|
430
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[54]), vec![30]);
|
|
431
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[55]), vec![0, 1]); // 55 is the 10 indexed Fibonacci number, which is the 8 indexed effective Fibonacci number, and therefore is the first number needing two bytes to contain these 8 bits, because there is 1 "use bit" and 7 "skip bits" in the effective zeckendorf bits ascending.
|
|
432
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[255]), vec![33, 2]);
|
|
433
|
+
* assert_eq!(padless_zeckendorf_compress_le_dangerous(&[0, 1]), vec![34, 2]);
|
|
436
434
|
* ```
|
|
437
435
|
* @param {Uint8Array} data
|
|
438
436
|
* @returns {Uint8Array}
|
|
439
437
|
*/
|
|
440
|
-
export function
|
|
438
|
+
export function padless_zeckendorf_compress_le_dangerous(data) {
|
|
441
439
|
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
442
440
|
const len0 = WASM_VECTOR_LEN;
|
|
443
|
-
const ret = wasm.
|
|
441
|
+
const ret = wasm.padless_zeckendorf_compress_le_dangerous(ptr0, len0);
|
|
444
442
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
445
443
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
446
444
|
return v2;
|
|
@@ -449,7 +447,15 @@ export function zeckendorf_compress_le_broken_do_not_use(data) {
|
|
|
449
447
|
/**
|
|
450
448
|
* Decompresses a slice of bytes compressed using the Zeckendorf algorithm, assuming the original data was compressed using the big endian bytes interpretation.
|
|
451
449
|
*
|
|
452
|
-
* Assume the original input data was interpreted as a big endian integer, for now. See the TODO in the [`
|
|
450
|
+
* Assume the original input data was interpreted as a big endian integer, for now. See the TODO in the [`padless_zeckendorf_compress_be_dangerous`] function for more information.
|
|
451
|
+
*
|
|
452
|
+
* # ⚠️ Important: Leading Zero Padding
|
|
453
|
+
*
|
|
454
|
+
* **This function does not pad leading zero bytes.** If the original data had leading zeros, they will not be restored.
|
|
455
|
+
* The decompressed output will be the minimal representation of the number (without leading zeros).
|
|
456
|
+
*
|
|
457
|
+
* For a format that automatically handles size preservation and padding, use [`crate::zeck_file_format::file::deserialize_zeck_file`]
|
|
458
|
+
* and [`crate::zeck_file_format::decompress::decompress_zeck_file`] instead, which includes a header with the original size information and restores leading zeros.
|
|
453
459
|
*
|
|
454
460
|
* # ⚠️ Warning
|
|
455
461
|
*
|
|
@@ -459,20 +465,20 @@ export function zeckendorf_compress_le_broken_do_not_use(data) {
|
|
|
459
465
|
* # Examples
|
|
460
466
|
*
|
|
461
467
|
* ```
|
|
462
|
-
* # use zeck::
|
|
463
|
-
* assert_eq!(
|
|
464
|
-
* assert_eq!(
|
|
465
|
-
* assert_eq!(
|
|
466
|
-
* assert_eq!(
|
|
467
|
-
* assert_eq!(
|
|
468
|
+
* # use zeck::padless_zeckendorf_decompress_be_dangerous;
|
|
469
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[0]), vec![0]);
|
|
470
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[1]), vec![1]);
|
|
471
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[0b111]), vec![12]);
|
|
472
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[33, 2]), vec![255]);
|
|
473
|
+
* assert_eq!(padless_zeckendorf_decompress_be_dangerous(&[34, 2]), vec![1, 0]);
|
|
468
474
|
* ```
|
|
469
475
|
* @param {Uint8Array} compressed_data
|
|
470
476
|
* @returns {Uint8Array}
|
|
471
477
|
*/
|
|
472
|
-
export function
|
|
478
|
+
export function padless_zeckendorf_decompress_be_dangerous(compressed_data) {
|
|
473
479
|
const ptr0 = passArray8ToWasm0(compressed_data, wasm.__wbindgen_malloc);
|
|
474
480
|
const len0 = WASM_VECTOR_LEN;
|
|
475
|
-
const ret = wasm.
|
|
481
|
+
const ret = wasm.padless_zeckendorf_decompress_be_dangerous(ptr0, len0);
|
|
476
482
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
477
483
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
478
484
|
return v2;
|
|
@@ -481,6 +487,14 @@ export function zeckendorf_decompress_be_broken_do_not_use(compressed_data) {
|
|
|
481
487
|
/**
|
|
482
488
|
* Decompresses a slice of bytes compressed using the Zeckendorf algorithm, assuming the original data was compressed using the little endian bytes interpretation.
|
|
483
489
|
*
|
|
490
|
+
* # ⚠️ Important: Leading Zero Padding
|
|
491
|
+
*
|
|
492
|
+
* **This function does not pad leading zero bytes.** If the original data had leading zeros, they will not be restored.
|
|
493
|
+
* The decompressed output will be the minimal representation of the number (without leading zeros).
|
|
494
|
+
*
|
|
495
|
+
* For a format that automatically handles size preservation and padding, use [`crate::zeck_file_format::file::deserialize_zeck_file`]
|
|
496
|
+
* and [`crate::zeck_file_format::decompress::decompress_zeck_file`] instead, which includes a header with the original size information and restores leading zeros.
|
|
497
|
+
*
|
|
484
498
|
* # ⚠️ Warning
|
|
485
499
|
*
|
|
486
500
|
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
@@ -489,20 +503,44 @@ export function zeckendorf_decompress_be_broken_do_not_use(compressed_data) {
|
|
|
489
503
|
* # Examples
|
|
490
504
|
*
|
|
491
505
|
* ```
|
|
492
|
-
* # use zeck::
|
|
493
|
-
* assert_eq!(
|
|
494
|
-
* assert_eq!(
|
|
495
|
-
* assert_eq!(
|
|
496
|
-
* assert_eq!(
|
|
497
|
-
* assert_eq!(
|
|
506
|
+
* # use zeck::padless_zeckendorf_decompress_le_dangerous;
|
|
507
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[0]), vec![0]);
|
|
508
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[1]), vec![1]);
|
|
509
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[0b111]), vec![12]);
|
|
510
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[33, 2]), vec![255]);
|
|
511
|
+
* assert_eq!(padless_zeckendorf_decompress_le_dangerous(&[34, 2]), vec![0, 1]);
|
|
498
512
|
* ```
|
|
499
513
|
* @param {Uint8Array} compressed_data
|
|
500
514
|
* @returns {Uint8Array}
|
|
501
515
|
*/
|
|
502
|
-
export function
|
|
516
|
+
export function padless_zeckendorf_decompress_le_dangerous(compressed_data) {
|
|
503
517
|
const ptr0 = passArray8ToWasm0(compressed_data, wasm.__wbindgen_malloc);
|
|
504
518
|
const len0 = WASM_VECTOR_LEN;
|
|
505
|
-
const ret = wasm.
|
|
519
|
+
const ret = wasm.padless_zeckendorf_decompress_le_dangerous(ptr0, len0);
|
|
520
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
521
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
522
|
+
return v2;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Unpacks a vector of bytes into a vector of bits (0s and 1s) from an ezba (Effective Zeckendorf Bits Ascending).
|
|
527
|
+
*
|
|
528
|
+
* # Examples
|
|
529
|
+
*
|
|
530
|
+
* ```
|
|
531
|
+
* # use zeck::unpack_bytes_to_ezba_bits;
|
|
532
|
+
* assert_eq!(unpack_bytes_to_ezba_bits(&[0]), vec![0, 0, 0, 0, 0, 0, 0, 0]);
|
|
533
|
+
* assert_eq!(unpack_bytes_to_ezba_bits(&[1]), vec![1, 0, 0, 0, 0, 0, 0, 0]);
|
|
534
|
+
* assert_eq!(unpack_bytes_to_ezba_bits(&[0b111]), vec![1, 1, 1, 0, 0, 0, 0, 0]);
|
|
535
|
+
* assert_eq!(unpack_bytes_to_ezba_bits(&[1, 1]), vec![1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]);
|
|
536
|
+
* ```
|
|
537
|
+
* @param {Uint8Array} bytes
|
|
538
|
+
* @returns {Uint8Array}
|
|
539
|
+
*/
|
|
540
|
+
export function unpack_bytes_to_ezba_bits(bytes) {
|
|
541
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
542
|
+
const len0 = WASM_VECTOR_LEN;
|
|
543
|
+
const ret = wasm.unpack_bytes_to_ezba_bits(ptr0, len0);
|
|
506
544
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
507
545
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
508
546
|
return v2;
|
package/zeck_bg.wasm
CHANGED
|
Binary file
|