ruby-ole 1.2.11.4 → 1.2.11.5
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +7 -0
- data/lib/ole/ranges_io.rb +3 -3
- data/lib/ole/storage/base.rb +7 -12
- data/lib/ole/storage/file_system.rb +1 -1
- data/lib/ole/storage/version.rb +1 -1
- data/lib/ole/support.rb +26 -38
- data/test/test_ranges_io.rb +11 -1
- data/test/test_support.rb +4 -13
- metadata +4 -4
data/ChangeLog
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 1.2.11.5 / 2012-11-06
|
2
|
+
|
3
|
+
- Fix breakage of IO.parse_mode on Rubinius (issue #10).
|
4
|
+
- Make tests pass on rubinius (issue #11).
|
5
|
+
- Improve RangesIO test coverage.
|
6
|
+
- Don't warn when mbat_start is AVAIL instead of EOC (github #9).
|
7
|
+
|
1
8
|
== 1.2.11.4 / 2012-07-03
|
2
9
|
|
3
10
|
- Embed PropertySet meta data GUIDs and field lists, to avoid hitting the
|
data/lib/ole/ranges_io.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: ASCII-8BIT
|
2
2
|
|
3
|
-
# need
|
3
|
+
# need Ole::IOMode
|
4
4
|
require 'ole/support'
|
5
5
|
|
6
6
|
#
|
@@ -57,7 +57,7 @@ class RangesIO
|
|
57
57
|
mode, params = 'r', mode if Hash === mode
|
58
58
|
ranges = params[:ranges]
|
59
59
|
@params = {:close_parent => false}.merge params
|
60
|
-
@mode =
|
60
|
+
@mode = Ole::IOMode.new mode
|
61
61
|
@io = io
|
62
62
|
# initial position in the file
|
63
63
|
@pos = 0
|
@@ -255,7 +255,7 @@ end
|
|
255
255
|
class RangesIONonResizeable < RangesIO # :nodoc:
|
256
256
|
def initialize io, mode='r', params={}
|
257
257
|
mode, params = 'r', mode if Hash === mode
|
258
|
-
flags =
|
258
|
+
flags = Ole::IOMode.new(mode).flags & ~IO::TRUNC
|
259
259
|
super io, flags, params
|
260
260
|
end
|
261
261
|
end
|
data/lib/ole/storage/base.rb
CHANGED
@@ -50,21 +50,16 @@ module Ole # :nodoc:
|
|
50
50
|
raise ArgumentError, 'unable to specify mode string with io object' if mode
|
51
51
|
[false, arg]
|
52
52
|
end
|
53
|
-
# do we have this file opened for writing?
|
54
|
-
#
|
55
|
-
# hmmm, note that in ruby 1.9 this doesn't work anymore. which is all the more
|
56
|
-
# reason to use mode string parsing when available, and fall back to something like
|
57
|
-
# io.writeable? otherwise.
|
53
|
+
# do we have this file opened for writing? use mode when provided,
|
54
|
+
# otherwise try no-op methods which will raise if read-only
|
58
55
|
@writeable = begin
|
59
56
|
if mode
|
60
|
-
|
57
|
+
IOMode.new(mode).writeable?
|
61
58
|
else
|
59
|
+
# works on mri 1.8 & jruby
|
62
60
|
@io.flush
|
63
|
-
#
|
64
|
-
|
65
|
-
if RUBY_PLATFORM != 'java' and @io.respond_to?(:syswrite)
|
66
|
-
@io.syswrite('')
|
67
|
-
end
|
61
|
+
# works on mri 1.9 & rubinius
|
62
|
+
@io.write_nonblock('') if @io.respond_to?(:write_nonblock)
|
68
63
|
true
|
69
64
|
end
|
70
65
|
rescue IOError
|
@@ -390,7 +385,7 @@ module Ole # :nodoc:
|
|
390
385
|
# 3 for this value.
|
391
386
|
# transacting_signature != "\x00" * 4 or
|
392
387
|
if threshold != 4096 or
|
393
|
-
num_mbat == 0 &&
|
388
|
+
num_mbat == 0 && ![AllocationTable::EOC, AllocationTable::AVAIL].include?(mbat_start) or
|
394
389
|
reserved != "\x00" * 6
|
395
390
|
Log.warn "may not be a valid OLE2 structured storage file"
|
396
391
|
end
|
data/lib/ole/storage/version.rb
CHANGED
data/lib/ole/support.rb
CHANGED
@@ -11,14 +11,6 @@ require 'stringio'
|
|
11
11
|
require 'enumerator'
|
12
12
|
|
13
13
|
class String # :nodoc:
|
14
|
-
# plural of String#index. returns all offsets of +string+. rename to indices?
|
15
|
-
#
|
16
|
-
# note that it doesn't check for overlapping values.
|
17
|
-
def indexes string
|
18
|
-
# in some ways i'm surprised that $~ works properly in this case...
|
19
|
-
to_enum(:scan, /#{Regexp.quote string}/m).map { $~.begin 0 }
|
20
|
-
end
|
21
|
-
|
22
14
|
def each_chunk size
|
23
15
|
(length / size.to_f).ceil.times { |i| yield self[i * size, size] }
|
24
16
|
end
|
@@ -165,34 +157,8 @@ module RecursivelyEnumerable # :nodoc:
|
|
165
157
|
end
|
166
158
|
end
|
167
159
|
|
168
|
-
|
169
|
-
class
|
170
|
-
# this is for jruby
|
171
|
-
include File::Constants unless defined?(RDONLY)
|
172
|
-
|
173
|
-
# nabbed from rubinius, and modified
|
174
|
-
def self.parse_mode mode
|
175
|
-
ret = 0
|
176
|
-
|
177
|
-
case mode[0, 1]
|
178
|
-
when 'r'; ret |= RDONLY
|
179
|
-
when 'w'; ret |= WRONLY | CREAT | TRUNC
|
180
|
-
when 'a'; ret |= WRONLY | CREAT | APPEND
|
181
|
-
else raise ArgumentError, "illegal access mode #{mode}"
|
182
|
-
end
|
183
|
-
|
184
|
-
(1...mode.length).each do |i|
|
185
|
-
case mode[i, 1]
|
186
|
-
when '+'; ret = (ret & ~(RDONLY | WRONLY)) | RDWR
|
187
|
-
when 'b'; ret |= Mode::BINARY
|
188
|
-
else raise ArgumentError, "illegal access mode #{mode}"
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
ret
|
193
|
-
end
|
194
|
-
|
195
|
-
class Mode
|
160
|
+
module Ole
|
161
|
+
class IOMode
|
196
162
|
# ruby 1.9 defines binary as 0, which isn't very helpful.
|
197
163
|
# its 4 in rubinius. no longer using
|
198
164
|
#
|
@@ -207,9 +173,31 @@ class IO
|
|
207
173
|
include Constants
|
208
174
|
NAMES = %w[rdonly wronly rdwr creat trunc append binary]
|
209
175
|
|
176
|
+
# nabbed from rubinius, and modified
|
177
|
+
def self.parse_mode mode
|
178
|
+
ret = 0
|
179
|
+
|
180
|
+
case mode[0, 1]
|
181
|
+
when 'r'; ret |= RDONLY
|
182
|
+
when 'w'; ret |= WRONLY | CREAT | TRUNC
|
183
|
+
when 'a'; ret |= WRONLY | CREAT | APPEND
|
184
|
+
else raise ArgumentError, "illegal access mode #{mode}"
|
185
|
+
end
|
186
|
+
|
187
|
+
(1...mode.length).each do |i|
|
188
|
+
case mode[i, 1]
|
189
|
+
when '+'; ret = (ret & ~(RDONLY | WRONLY)) | RDWR
|
190
|
+
when 'b'; ret |= BINARY
|
191
|
+
else raise ArgumentError, "illegal access mode #{mode}"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
ret
|
196
|
+
end
|
197
|
+
|
210
198
|
attr_reader :flags
|
211
199
|
def initialize flags
|
212
|
-
flags =
|
200
|
+
flags = self.class.parse_mode flags.to_str if flags.respond_to? :to_str
|
213
201
|
raise ArgumentError, "invalid flags - #{flags.inspect}" unless Fixnum === flags
|
214
202
|
@flags = flags
|
215
203
|
end
|
@@ -251,7 +239,7 @@ class IO
|
|
251
239
|
=end
|
252
240
|
|
253
241
|
def inspect
|
254
|
-
names = NAMES.map { |name| name if (flags &
|
242
|
+
names = NAMES.map { |name| name if (flags & IOMode.const_get(name.upcase)) != 0 }
|
255
243
|
names.unshift 'rdonly' if (flags & 0x3) == 0
|
256
244
|
"#<#{self.class} #{names.compact * '|'}>"
|
257
245
|
end
|
data/test/test_ranges_io.rb
CHANGED
@@ -29,6 +29,14 @@ class TestRangesIO < Test::Unit::TestCase
|
|
29
29
|
assert_equal true, f.closed?
|
30
30
|
end
|
31
31
|
|
32
|
+
def test_combine
|
33
|
+
ranges = [[0, 100], 100...200, [200, 100]]
|
34
|
+
io = RangesIO.new STDOUT, 'r+', :ranges => ranges
|
35
|
+
assert_equal [[0, 300]], io.ranges
|
36
|
+
io = RangesIO.new STDOUT, 'r+', :ranges => ranges, :combine => false
|
37
|
+
assert_equal [[0, 100], [100, 100], [200, 100]], io.ranges
|
38
|
+
end
|
39
|
+
|
32
40
|
def test_basics
|
33
41
|
assert_equal 160, @io.size
|
34
42
|
assert_match %r{size=160}, @io.inspect
|
@@ -44,6 +52,8 @@ class TestRangesIO < Test::Unit::TestCase
|
|
44
52
|
@io.seek(-10, IO::SEEK_CUR)
|
45
53
|
@io.pos += 20
|
46
54
|
assert_equal 70, @io.pos
|
55
|
+
@io.rewind
|
56
|
+
assert_equal 0, @io.pos
|
47
57
|
# seeking past the end doesn't throw an exception for normal
|
48
58
|
# files, even in read mode, but RangesIO does
|
49
59
|
assert_raises(Errno::EINVAL) { @io.seek 500 }
|
@@ -97,7 +107,7 @@ class TestRangesIO < Test::Unit::TestCase
|
|
97
107
|
end
|
98
108
|
# will be fine
|
99
109
|
@io = RangesIONonResizeable.new(StringIO.new, 'w', :ranges => [])
|
100
|
-
assert_equal '#<
|
110
|
+
assert_equal '#<Ole::IOMode wronly|creat>', @io.instance_variable_get(:@mode).inspect
|
101
111
|
end
|
102
112
|
end
|
103
113
|
|
data/test/test_support.rb
CHANGED
@@ -36,15 +36,6 @@ class TestSupport < Test::Unit::TestCase
|
|
36
36
|
assert_equal str, dst.string
|
37
37
|
end
|
38
38
|
|
39
|
-
def test_string
|
40
|
-
str = "aa aa ||| aa aa"
|
41
|
-
assert_equal [0, 3, 10, 13], str.indexes('aa')
|
42
|
-
# this is mostly a check that regexp quote is used.
|
43
|
-
assert_equal [6, 7, 8], str.indexes('|')
|
44
|
-
# note not [6, 7] - no overlaps
|
45
|
-
assert_equal [6], str.indexes('||')
|
46
|
-
end
|
47
|
-
|
48
39
|
def test_symbol
|
49
40
|
array = (1..10).to_a
|
50
41
|
assert_equal 55, array.inject(&:+)
|
@@ -53,7 +44,7 @@ end
|
|
53
44
|
|
54
45
|
class TestIOMode < Test::Unit::TestCase
|
55
46
|
def mode s
|
56
|
-
|
47
|
+
Ole::IOMode.new s
|
57
48
|
end
|
58
49
|
|
59
50
|
def test_parse
|
@@ -83,9 +74,9 @@ class TestIOMode < Test::Unit::TestCase
|
|
83
74
|
end
|
84
75
|
|
85
76
|
def test_inspect
|
86
|
-
assert_equal '#<
|
87
|
-
assert_equal '#<
|
88
|
-
assert_equal '#<
|
77
|
+
assert_equal '#<Ole::IOMode rdonly>', mode('r').inspect
|
78
|
+
assert_equal '#<Ole::IOMode rdwr|creat|trunc|binary>', mode('wb+').inspect
|
79
|
+
assert_equal '#<Ole::IOMode wronly|creat|append>', mode('a').inspect
|
89
80
|
end
|
90
81
|
end
|
91
82
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-ole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 105
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
9
|
- 11
|
10
|
-
-
|
11
|
-
version: 1.2.11.
|
10
|
+
- 5
|
11
|
+
version: 1.2.11.5
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Charles Lowe
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-11-06 00:00:00 +11:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|