lz77 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -0
- data/lib/lz77.rb +1 -0
- data/lib/lz77/decoder.rb +44 -0
- metadata +47 -0
data/README.rdoc
ADDED
data/lib/lz77.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'lz77/decoder'
|
data/lib/lz77/decoder.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module LZ77
|
4
|
+
# Decodes a string with LZ77 compression.
|
5
|
+
#
|
6
|
+
# Params:
|
7
|
+
# string: (String) encoded string
|
8
|
+
#
|
9
|
+
# Returns: (String) decoded string
|
10
|
+
def self.decode(string)
|
11
|
+
result = ''
|
12
|
+
i = 0
|
13
|
+
|
14
|
+
while i < string.size
|
15
|
+
b = string[i].ord
|
16
|
+
|
17
|
+
if b == 0x00 or (0x09 <= b and b <= 0x7f)
|
18
|
+
result << b.chr
|
19
|
+
elsif 0x01 <= b and b <= 0x08
|
20
|
+
b.times do |j|
|
21
|
+
bb = string[i + j + 1]
|
22
|
+
result << bb.chr
|
23
|
+
end
|
24
|
+
|
25
|
+
i += b
|
26
|
+
elsif 0x80 <= b and b <= 0xbf
|
27
|
+
b = (b << 8) + string[i + 1].ord
|
28
|
+
s = result[(-1 * ((b & 0x3ff8) >> 3)), ((b & 0x0007) + 3)]
|
29
|
+
|
30
|
+
s.each_byte do |bb|
|
31
|
+
result << bb.chr
|
32
|
+
end
|
33
|
+
|
34
|
+
i += 1
|
35
|
+
elsif 0xc0 <= b and b <= 0xff
|
36
|
+
result << ' ' + (b ^ 0x80).chr
|
37
|
+
end
|
38
|
+
|
39
|
+
i += 1
|
40
|
+
end
|
41
|
+
|
42
|
+
return result
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lz77
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- karaszandris
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-02 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: LZ-77 compressor/decompressor
|
15
|
+
email: karaszandris@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/lz77.rb
|
21
|
+
- lib/lz77/decoder.rb
|
22
|
+
- README.rdoc
|
23
|
+
homepage: http://rubygems.org/gem/lz77
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.23
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: LZ-77 coder
|
47
|
+
test_files: []
|