Sha256: 2840ae0a2d9e2d535b74758337af4fca3b26913908f2890f8821eecd3e5857bc

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

#!ruby

require "extlzham"

# directly string encode / decode
p data = LZHAM.encode("abcdefghijklmnopqrstuvwxyz" * 10)
p LZHAM.decode(data)


# directly string encode / decode with dictionaly size
# (IMPORTANT! MUST BE SAME SIZE both encoding and decoding)
dictsize = 20 # log(2)'d dictionaly size. This case is 1 MiB (2 ** 20).
p data = LZHAM.encode("abcdefghijklmnopqrstuvwxyz" * 10, dictsize: dictsize)
p LZHAM.decode(data, dictsize: dictsize)


# streaming processing

# setup streaming data
ss = StringIO.new("abcdefghijklmnopqrstuvwxyz" * 10) # source stream
es = StringIO.new # encoded stream
ds = StringIO.new # destination stream

# streaming encode with block
ss.rewind
es.rewind
LZHAM.encode(es) { |lzham| lzham << ss.read }

# streaming encode without block
ss.rewind
es.rewind
lzham = LZHAM.encode(es)
lzham << ss.read
lzham.finish # or lzham.close

# streaming decode with block
ss.rewind
es.rewind
ds.rewind
LZHAM.decode(ds) { |lzham| lzham << es.read }

# streaming decode without block
ss.rewind
es.rewind
ds.rewind
lzham = LZHAM.decode(ds)
lzham << es.read
lzham.finish # or lzham.close

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
extlzham-0.0.1.PROTOTYPE3-x86-mingw32 examples/basic.rb
extlzham-0.0.1.PROTOTYPE3 examples/basic.rb
extlzham-0.0.1.PROTOTYPE2 examples/basic.rb
extlzham-0.0.1.PROTOTYPE examples/basic.rb
extlzham-0.0.1.PROTOTYPE-x86-mingw32 examples/basic.rb