Skip to content

Commit

Permalink
FEAT: partial crush decompression
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Dec 10, 2021
1 parent d744cee commit f64cd37
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/core/u-crush.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ static inline int get_penalty(int a, int b) {
ctx.bit_count = 0;
ctx.bit_buf = 0;

// allow partial output if specified...
if (limit && size > limit) size = limit;

ser = Make_Binary(size); // output series
buf = BIN_HEAD(ser); // output binary

Expand Down
6 changes: 3 additions & 3 deletions src/tests/units/compress-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ text: {Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempo
--assert text = to string! decompress compress/level text 'crush 1 'crush
--assert text = to string! decompress compress/level text 'crush 2 'crush

; --test-- "CRUSH decompression with specified uncompressed size"
; bin: compress data 'crush
; --assert #{74657374} = decompress/size bin 'crush 4
--test-- "CRUSH decompression with specified uncompressed size"
bin: compress data 'crush
--assert #{74657374} = decompress/size bin 'crush 4

--test-- "CRUSH compression when input is limited"
--assert #{74657374} = decompress compress/part data 'crush 4 'crush
Expand Down

0 comments on commit f64cd37

Please sign in to comment.