ruby-lzws 1.0.0 → 1.1.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.
- checksums.yaml +4 -4
- data/README.md +176 -27
- data/ext/extconf.rb +11 -17
- data/ext/lzws_ext/buffer.c +18 -0
- data/ext/lzws_ext/buffer.h +11 -0
- data/ext/lzws_ext/common.h +4 -0
- data/ext/lzws_ext/error.c +33 -3
- data/ext/lzws_ext/error.h +20 -1
- data/ext/lzws_ext/io.c +60 -47
- data/ext/lzws_ext/io.h +2 -0
- data/ext/lzws_ext/macro.h +0 -2
- data/ext/lzws_ext/main.c +8 -29
- data/ext/lzws_ext/option.c +23 -10
- data/ext/lzws_ext/option.h +27 -50
- data/ext/lzws_ext/stream/compressor.c +71 -84
- data/ext/lzws_ext/stream/compressor.h +5 -2
- data/ext/lzws_ext/stream/decompressor.c +67 -84
- data/ext/lzws_ext/stream/decompressor.h +4 -1
- data/ext/lzws_ext/string.c +261 -44
- data/ext/lzws_ext/string.h +2 -0
- data/lib/lzws/error.rb +8 -7
- data/lib/lzws/file.rb +6 -18
- data/lib/lzws/option.rb +10 -7
- data/lib/lzws/stream/abstract.rb +2 -2
- data/lib/lzws/stream/raw/abstract.rb +24 -9
- data/lib/lzws/stream/raw/compressor.rb +7 -31
- data/lib/lzws/stream/raw/decompressor.rb +6 -24
- data/lib/lzws/stream/reader.rb +14 -11
- data/lib/lzws/stream/reader_helpers.rb +3 -3
- data/lib/lzws/stream/writer_helpers.rb +2 -2
- data/lib/lzws/string.rb +4 -2
- data/lib/lzws/version.rb +1 -1
- data/lib/lzws.rb +4 -1
- metadata +5 -3
@@ -4,7 +4,6 @@
|
|
4
4
|
require "lzws_ext"
|
5
5
|
|
6
6
|
require_relative "abstract"
|
7
|
-
require_relative "../../error"
|
8
7
|
require_relative "../../option"
|
9
8
|
require_relative "../../validation"
|
10
9
|
|
@@ -12,13 +11,13 @@ module LZWS
|
|
12
11
|
module Stream
|
13
12
|
module Raw
|
14
13
|
class Decompressor < Abstract
|
14
|
+
BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
|
15
|
+
|
15
16
|
def initialize(options = {})
|
16
|
-
options = Option.get_decompressor_options options
|
17
|
+
options = Option.get_decompressor_options options, BUFFER_LENGTH_NAMES
|
17
18
|
native_stream = NativeDecompressor.new options
|
18
19
|
|
19
20
|
super native_stream
|
20
|
-
|
21
|
-
@need_to_read_magic_header = !options[:without_magic_header]
|
22
21
|
end
|
23
22
|
|
24
23
|
def read(source, &writer)
|
@@ -29,19 +28,6 @@ module LZWS
|
|
29
28
|
|
30
29
|
total_bytes_read = 0
|
31
30
|
|
32
|
-
if @need_to_read_magic_header
|
33
|
-
bytes_read = @native_stream.read_magic_header source
|
34
|
-
if bytes_read == 0
|
35
|
-
# Decompressor is not able to read full magic header.
|
36
|
-
return 0
|
37
|
-
end
|
38
|
-
|
39
|
-
total_bytes_read += bytes_read
|
40
|
-
source = source.byteslice bytes_read, source.bytesize - bytes_read
|
41
|
-
|
42
|
-
@need_to_read_magic_header = false
|
43
|
-
end
|
44
|
-
|
45
31
|
loop do
|
46
32
|
bytes_read, need_more_destination = @native_stream.read source
|
47
33
|
total_bytes_read += bytes_read
|
@@ -59,19 +45,15 @@ module LZWS
|
|
59
45
|
total_bytes_read
|
60
46
|
end
|
61
47
|
|
62
|
-
def
|
63
|
-
|
48
|
+
def close(&writer)
|
49
|
+
return nil if closed?
|
64
50
|
|
65
51
|
Validation.validate_proc writer
|
66
52
|
|
67
|
-
|
53
|
+
super
|
68
54
|
|
69
55
|
nil
|
70
56
|
end
|
71
|
-
|
72
|
-
protected def do_not_use_after_close
|
73
|
-
raise UsedAfterCloseError, "decompressor used after close" if @is_closed
|
74
|
-
end
|
75
57
|
end
|
76
58
|
end
|
77
59
|
end
|
data/lib/lzws/stream/reader.rb
CHANGED
@@ -11,8 +11,6 @@ module LZWS
|
|
11
11
|
class Reader < Abstract
|
12
12
|
include ReaderHelpers
|
13
13
|
|
14
|
-
DEFAULT_IO_PORTION_BYTESIZE = 1 << 15 # 32 KB
|
15
|
-
|
16
14
|
attr_accessor :lineno
|
17
15
|
|
18
16
|
def initialize(source_io, options = {}, *args)
|
@@ -20,17 +18,22 @@ module LZWS
|
|
20
18
|
|
21
19
|
super source_io, *args
|
22
20
|
|
23
|
-
|
24
|
-
@options.delete :io_portion_bytesize
|
25
|
-
|
26
|
-
Validation.validate_positive_integer io_portion_bytesize unless io_portion_bytesize.nil?
|
27
|
-
@io_portion_bytesize = io_portion_bytesize || DEFAULT_IO_PORTION_BYTESIZE
|
28
|
-
|
21
|
+
initialize_source_buffer_length
|
29
22
|
reset_io_remainder
|
30
23
|
|
31
24
|
@lineno = 0
|
32
25
|
end
|
33
26
|
|
27
|
+
protected def initialize_source_buffer_length
|
28
|
+
source_buffer_length = @options[:source_buffer_length]
|
29
|
+
Validation.validate_not_negative_integer source_buffer_length unless source_buffer_length.nil?
|
30
|
+
|
31
|
+
source_buffer_length = Buffer::DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR \
|
32
|
+
if source_buffer_length == 0 || source_buffer_length.nil?
|
33
|
+
|
34
|
+
@source_buffer_length = source_buffer_length
|
35
|
+
end
|
36
|
+
|
34
37
|
protected def create_raw_stream
|
35
38
|
Raw::Decompressor.new @options
|
36
39
|
end
|
@@ -69,7 +72,7 @@ module LZWS
|
|
69
72
|
end
|
70
73
|
|
71
74
|
protected def read_more_from_buffer
|
72
|
-
io_data = @io.read @
|
75
|
+
io_data = @io.read @source_buffer_length
|
73
76
|
append_io_data_to_buffer io_data
|
74
77
|
end
|
75
78
|
|
@@ -82,7 +85,7 @@ module LZWS
|
|
82
85
|
end
|
83
86
|
|
84
87
|
protected def readpartial_from_buffer
|
85
|
-
io_data = @io.readpartial @
|
88
|
+
io_data = @io.readpartial @source_buffer_length
|
86
89
|
append_io_data_to_buffer io_data
|
87
90
|
end
|
88
91
|
|
@@ -111,7 +114,7 @@ module LZWS
|
|
111
114
|
end
|
112
115
|
|
113
116
|
protected def read_more_from_buffer_nonblock(*options)
|
114
|
-
io_data = @io.read_nonblock @
|
117
|
+
io_data = @io.read_nonblock @source_buffer_length, *options
|
115
118
|
append_io_data_to_buffer io_data
|
116
119
|
end
|
117
120
|
|
@@ -156,7 +156,7 @@ module LZWS
|
|
156
156
|
protected def ungetstring(string)
|
157
157
|
Validation.validate_string string
|
158
158
|
|
159
|
-
string = ::String.new string, :encoding => @internal_encoding
|
159
|
+
string = ::String.new string, :encoding => @internal_encoding unless @internal_encoding.nil?
|
160
160
|
string = transcode_to_external string unless @external_encoding.nil?
|
161
161
|
|
162
162
|
string.force_encoding ::Encoding::BINARY
|
@@ -172,8 +172,8 @@ module LZWS
|
|
172
172
|
Validation.validate_string file_path
|
173
173
|
Validation.validate_proc block
|
174
174
|
|
175
|
-
::File.open file_path, "rb" do |
|
176
|
-
reader = new
|
175
|
+
::File.open file_path, "rb" do |io|
|
176
|
+
reader = new io, *args
|
177
177
|
|
178
178
|
begin
|
179
179
|
yield reader
|
data/lib/lzws/string.rb
CHANGED
@@ -8,10 +8,12 @@ require_relative "validation"
|
|
8
8
|
|
9
9
|
module LZWS
|
10
10
|
module String
|
11
|
+
BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
|
12
|
+
|
11
13
|
def self.compress(source, options = {})
|
12
14
|
Validation.validate_string source
|
13
15
|
|
14
|
-
options = Option.get_compressor_options options
|
16
|
+
options = Option.get_compressor_options options, BUFFER_LENGTH_NAMES
|
15
17
|
|
16
18
|
LZWS._native_compress_string source, options
|
17
19
|
end
|
@@ -19,7 +21,7 @@ module LZWS
|
|
19
21
|
def self.decompress(source, options = {})
|
20
22
|
Validation.validate_string source
|
21
23
|
|
22
|
-
options = Option.get_decompressor_options options
|
24
|
+
options = Option.get_decompressor_options options, BUFFER_LENGTH_NAMES
|
23
25
|
|
24
26
|
LZWS._native_decompress_string source, options
|
25
27
|
end
|
data/lib/lzws/version.rb
CHANGED
data/lib/lzws.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lzws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Aladjev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitar
|
@@ -105,6 +105,8 @@ files:
|
|
105
105
|
- LICENSE
|
106
106
|
- README.md
|
107
107
|
- ext/extconf.rb
|
108
|
+
- ext/lzws_ext/buffer.c
|
109
|
+
- ext/lzws_ext/buffer.h
|
108
110
|
- ext/lzws_ext/common.h
|
109
111
|
- ext/lzws_ext/error.c
|
110
112
|
- ext/lzws_ext/error.h
|
@@ -156,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
158
|
- !ruby/object:Gem::Version
|
157
159
|
version: '0'
|
158
160
|
requirements: []
|
159
|
-
rubygems_version: 3.0.
|
161
|
+
rubygems_version: 3.0.6
|
160
162
|
signing_key:
|
161
163
|
specification_version: 4
|
162
164
|
summary: Ruby bindings for lzws library.
|