filter_io 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/filter_io.rb +10 -6
- data/lib/filter_io/version.rb +1 -1
- data/spec/filter_io_spec.rb +22 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9208b4c2d0df82cc91ed1cad2283a3d36218987c
|
4
|
+
data.tar.gz: a577f773a20e4e2be7bd219b01629d020a7522dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8edcd67f5b6220499dd21c6453d695eee991e8770f3ea48787fc1c72433275d8efe49c68fd27c48d0208edd76ad5bdf33e4fa612cc53e8a9f64e411a2348729d
|
7
|
+
data.tar.gz: ea4b663fbd4aca1f2d85259904c008ca30c23ee409c76876f039aa9120115c07ef0d8b5fffe58107b39f97de150bd9310539307bf3ea232b782fa57ac6bcb53f
|
data/lib/filter_io.rb
CHANGED
@@ -98,7 +98,7 @@ class FilterIO
|
|
98
98
|
nil
|
99
99
|
end
|
100
100
|
|
101
|
-
def read(length = nil)
|
101
|
+
def read(length = nil, buffer = nil)
|
102
102
|
raise ArgumentError if length && length < 0
|
103
103
|
return '' if length == 0
|
104
104
|
|
@@ -116,7 +116,7 @@ class FilterIO
|
|
116
116
|
else
|
117
117
|
length
|
118
118
|
end
|
119
|
-
data = pop_bytes read_length
|
119
|
+
data = pop_bytes read_length, buffer
|
120
120
|
@pos += data.bytesize
|
121
121
|
if length.nil?
|
122
122
|
data.force_encoding external_encoding if external_encoding
|
@@ -249,15 +249,19 @@ class FilterIO
|
|
249
249
|
str
|
250
250
|
end
|
251
251
|
|
252
|
-
def pop_bytes(count)
|
253
|
-
|
252
|
+
def pop_bytes(count, output_buffer = nil)
|
253
|
+
begin
|
254
254
|
org_encoding = @buffer.encoding
|
255
255
|
@buffer.force_encoding 'ASCII-8BIT'
|
256
|
-
@buffer.slice!(0, count)
|
256
|
+
data = @buffer.slice!(0, count)
|
257
|
+
if output_buffer
|
258
|
+
output_buffer.replace data
|
259
|
+
else
|
260
|
+
data
|
261
|
+
end
|
257
262
|
ensure
|
258
263
|
@buffer.force_encoding org_encoding
|
259
264
|
end
|
260
|
-
data
|
261
265
|
end
|
262
266
|
|
263
267
|
def buffer_data(block_size = nil)
|
data/lib/filter_io/version.rb
CHANGED
data/spec/filter_io_spec.rb
CHANGED
@@ -309,6 +309,14 @@ describe FilterIO do
|
|
309
309
|
expect(io.pos).to eq 2
|
310
310
|
end
|
311
311
|
|
312
|
+
it 'supports reading into user buffer' do
|
313
|
+
io = FilterIO.new(StringIO.new('foo bar'))
|
314
|
+
buffer = 'abcdef'
|
315
|
+
result = io.read(3, buffer)
|
316
|
+
expect(result.object_id).to eq buffer.object_id
|
317
|
+
expect(result).to eq 'foo'
|
318
|
+
end
|
319
|
+
|
312
320
|
it 'allows filtering of input with a block' do
|
313
321
|
input = 'foo bar'
|
314
322
|
expected = 'FOO BAR'
|
@@ -808,4 +816,18 @@ describe FilterIO do
|
|
808
816
|
end
|
809
817
|
expect(io.read).to eq 'TEST'
|
810
818
|
end
|
819
|
+
|
820
|
+
it 'supports IO.copy_stream' do
|
821
|
+
input = StringIO.new "Test"
|
822
|
+
output = StringIO.new
|
823
|
+
|
824
|
+
filtered_input = FilterIO.new input do |data|
|
825
|
+
data.upcase
|
826
|
+
end
|
827
|
+
|
828
|
+
IO.copy_stream(filtered_input, output)
|
829
|
+
|
830
|
+
output.rewind
|
831
|
+
expect(output.read).to eq 'TEST'
|
832
|
+
end
|
811
833
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filter_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Weathered
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.2.
|
120
|
+
rubygems_version: 2.2.2
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Filter IO streams with a block. Ruby's FilterInputStream.
|