! Copyright (C) 2023 Raghu Ranganathan. ! See https://factorcode.org/license.txt for BSD license. USING: io byte-arrays math io.encodings.binary io.streams.duplex kernel namespaces sbufs sequences sequences.repeating ; IN: compression.ulz : cpy ( sbuf len -- sbuf ) dup 0x40 bitand 0 = [ 0x3f bitand ] dip [ 8 shift read1 bitor ] unless read1 swap [ dupd 1 + tail-slice* ] dip 4 + append ; : ulz-decode ( istream -- sbuf ) 256 swap [ [ read1 ] [ dup 0x80 bitand 0 = [ 1 + read append ] [ cpy ] if ] while* ] with-input-stream ;