multipart-post 1.1.5 → 1.2.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.
- data/Gemfile.lock +1 -1
- data/History.txt +4 -0
- data/lib/composite_io.rb +26 -25
- data/lib/multipart_post.rb +2 -2
- data/multipart-post.gemspec +1 -0
- data/test/test_composite_io.rb +40 -2
- metadata +5 -4
data/Gemfile.lock
CHANGED
data/History.txt
CHANGED
data/lib/composite_io.rb
CHANGED
@@ -17,39 +17,40 @@ class CompositeReadIO
|
|
17
17
|
# respond to #read in a manner consistent with IO.
|
18
18
|
def initialize(*ios)
|
19
19
|
@ios = ios.flatten
|
20
|
+
@index = 0
|
20
21
|
end
|
21
22
|
|
22
|
-
# Read from
|
23
|
-
def read(
|
24
|
-
|
25
|
-
|
26
|
-
partial_amount = amount
|
27
|
-
parts = @ios.dup
|
23
|
+
# Read from IOs in order until `length` bytes have been received.
|
24
|
+
def read(length = nil, outbuf = nil)
|
25
|
+
got_result = false
|
26
|
+
outbuf = outbuf ? outbuf.replace("") : ""
|
28
27
|
|
29
|
-
|
30
|
-
result =
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
while io = current_io
|
29
|
+
if result = io.read(length)
|
30
|
+
got_result ||= !result.nil?
|
31
|
+
result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
|
32
|
+
outbuf << result
|
33
|
+
length -= result.length if length
|
34
|
+
break if length == 0
|
34
35
|
end
|
35
|
-
|
36
|
-
result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
|
37
|
-
buffer << result if result
|
38
|
-
partial_amount -= result.length if partial_amount && result != done
|
39
|
-
|
40
|
-
break if partial_amount && partial_amount <= 0
|
41
|
-
break if result == done
|
42
|
-
end
|
43
|
-
|
44
|
-
if buffer.length > 0
|
45
|
-
buffer
|
46
|
-
else
|
47
|
-
done
|
36
|
+
advance_io
|
48
37
|
end
|
38
|
+
(!got_result && length) ? nil : outbuf
|
49
39
|
end
|
50
|
-
|
40
|
+
|
51
41
|
def rewind
|
52
42
|
@ios.each { |io| io.rewind }
|
43
|
+
@index = 0
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def current_io
|
49
|
+
@ios[@index]
|
50
|
+
end
|
51
|
+
|
52
|
+
def advance_io
|
53
|
+
@index += 1
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
data/lib/multipart_post.rb
CHANGED
data/multipart-post.gemspec
CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["nick@nicksieger.com"]
|
10
10
|
s.homepage = "https://github.com/nicksieger/multipart-post"
|
11
11
|
s.summary = %q{A multipart form post accessory for Net::HTTP.}
|
12
|
+
s.license = "MIT"
|
12
13
|
s.description = %q{Use with Net::HTTP to do multipart form posts. IO values that have #content_type, #original_filename, and #local_path will be posted as a binary file.}
|
13
14
|
|
14
15
|
s.rubyforge_project = "caldersphere"
|
data/test/test_composite_io.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2007-
|
2
|
+
# Copyright (c) 2007-2013 Nick Sieger.
|
3
3
|
# See the file README.txt included with the distribution for
|
4
4
|
# software license details.
|
5
5
|
#++
|
@@ -7,6 +7,7 @@
|
|
7
7
|
require 'composite_io'
|
8
8
|
require 'stringio'
|
9
9
|
require 'test/unit'
|
10
|
+
require 'timeout'
|
10
11
|
|
11
12
|
class CompositeReadIOTest < Test::Unit::TestCase
|
12
13
|
def setup
|
@@ -23,7 +24,10 @@ class CompositeReadIOTest < Test::Unit::TestCase
|
|
23
24
|
utf8 = File.open(File.dirname(__FILE__)+'/multibyte.txt')
|
24
25
|
binary = StringIO.new("\x86")
|
25
26
|
@io = CompositeReadIO.new(binary,utf8)
|
26
|
-
|
27
|
+
|
28
|
+
expect = "\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB\n"
|
29
|
+
expect.force_encoding('BINARY') if expect.respond_to?(:force_encoding)
|
30
|
+
assert_equal expect, @io.read
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|
@@ -74,4 +78,38 @@ class CompositeReadIOTest < Test::Unit::TestCase
|
|
74
78
|
UploadIO.convert!('tmp.txt', 'text/plain', 'tmp.txt', 'tmp.txt')
|
75
79
|
}
|
76
80
|
end
|
81
|
+
|
82
|
+
## FIXME excluding on JRuby due to
|
83
|
+
## http://jira.codehaus.org/browse/JRUBY-7109
|
84
|
+
if IO.respond_to?(:copy_stream) && !defined?(JRUBY_VERSION)
|
85
|
+
def test_compatible_with_copy_stream
|
86
|
+
target_io = StringIO.new
|
87
|
+
Timeout.timeout(1) do
|
88
|
+
IO.copy_stream(@io, target_io)
|
89
|
+
end
|
90
|
+
assert_equal "the quick brown fox", target_io.string
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_empty
|
95
|
+
io = CompositeReadIO.new
|
96
|
+
assert_equal "", io.read
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_empty_limited
|
100
|
+
io = CompositeReadIO.new
|
101
|
+
assert_nil io.read(1)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_empty_parts
|
105
|
+
io = CompositeReadIO.new(StringIO.new, StringIO.new('the '), StringIO.new, StringIO.new('quick'))
|
106
|
+
assert_equal "the", io.read(3)
|
107
|
+
assert_equal " qu", io.read(3)
|
108
|
+
assert_equal "ick", io.read(4)
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_all_empty_parts
|
112
|
+
io = CompositeReadIO.new(StringIO.new, StringIO.new)
|
113
|
+
assert_nil io.read(1)
|
114
|
+
end
|
77
115
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multipart-post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'Use with Net::HTTP to do multipart form posts. IO values that have
|
15
15
|
#content_type, #original_filename, and #local_path will be posted as a binary file.'
|
@@ -38,7 +38,8 @@ files:
|
|
38
38
|
- test/test_composite_io.rb
|
39
39
|
- test/test_parts.rb
|
40
40
|
homepage: https://github.com/nicksieger/multipart-post
|
41
|
-
licenses:
|
41
|
+
licenses:
|
42
|
+
- MIT
|
42
43
|
post_install_message:
|
43
44
|
rdoc_options: []
|
44
45
|
require_paths:
|
@@ -57,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
58
|
version: '0'
|
58
59
|
requirements: []
|
59
60
|
rubyforge_project: caldersphere
|
60
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.24
|
61
62
|
signing_key:
|
62
63
|
specification_version: 3
|
63
64
|
summary: A multipart form post accessory for Net::HTTP.
|