http-form_data 2.3.0 → 3.0.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/CHANGELOG.md +161 -0
- data/LICENSE.txt +1 -1
- data/README.md +11 -10
- data/http-form_data.gemspec +28 -14
- data/lib/http/form_data/composite_io.rb +46 -28
- data/lib/http/form_data/file.rb +44 -19
- data/lib/http/form_data/multipart/param.rb +18 -48
- data/lib/http/form_data/multipart.rb +59 -12
- data/lib/http/form_data/part.rb +24 -2
- data/lib/http/form_data/readable.rb +24 -6
- data/lib/http/form_data/urlencoded.rb +100 -10
- data/lib/http/form_data/version.rb +1 -1
- data/lib/http/form_data.rb +38 -18
- data/sig/http/form_data/composite_io.rbs +32 -0
- data/sig/http/form_data/file.rbs +23 -0
- data/sig/http/form_data/multipart/param.rbs +23 -0
- data/sig/http/form_data/multipart.rbs +40 -0
- data/sig/http/form_data/part.rbs +16 -0
- data/sig/http/form_data/readable.rbs +19 -0
- data/sig/http/form_data/urlencoded.rbs +46 -0
- data/sig/http/form_data/version.rbs +5 -0
- data/sig/http/form_data.rbs +30 -0
- metadata +24 -43
- data/.editorconfig +0 -9
- data/.gitignore +0 -15
- data/.rspec +0 -2
- data/.rubocop.yml +0 -64
- data/.travis.yml +0 -34
- data/.yardopts +0 -2
- data/CHANGES.md +0 -96
- data/Gemfile +0 -26
- data/Guardfile +0 -16
- data/Rakefile +0 -24
- data/appveyor.yml +0 -8
- data/spec/fixtures/expected-multipart-body.tpl +0 -0
- data/spec/fixtures/the-http-gem.info +0 -1
- data/spec/lib/http/form_data/composite_io_spec.rb +0 -109
- data/spec/lib/http/form_data/file_spec.rb +0 -217
- data/spec/lib/http/form_data/multipart_spec.rb +0 -157
- data/spec/lib/http/form_data/part_spec.rb +0 -74
- data/spec/lib/http/form_data/urlencoded_spec.rb +0 -78
- data/spec/lib/http/form_data_spec.rb +0 -50
- data/spec/spec_helper.rb +0 -83
- data/spec/support/fixtures_helper.rb +0 -13
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Type signatures for the http-form_data gem
|
|
2
|
+
|
|
3
|
+
module HTTP
|
|
4
|
+
module FormData
|
|
5
|
+
CRLF: String
|
|
6
|
+
|
|
7
|
+
class Error < StandardError
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
type formdata = Multipart | Urlencoded
|
|
11
|
+
|
|
12
|
+
# Selects encoder type based on given data
|
|
13
|
+
def self.create: (untyped data, ?encoder: _Encoder?) -> formdata
|
|
14
|
+
|
|
15
|
+
# Coerces obj to Hash
|
|
16
|
+
def self.ensure_hash: (untyped obj) -> Hash[untyped, untyped]
|
|
17
|
+
|
|
18
|
+
# Coerces obj to an Enumerable of key-value pairs
|
|
19
|
+
def self.ensure_data: (untyped obj) -> untyped
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# Checks if data contains multipart data
|
|
24
|
+
def self.multipart?: (untyped data) -> bool
|
|
25
|
+
|
|
26
|
+
interface _Encoder
|
|
27
|
+
def call: (untyped data) -> String
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: http-form_data
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aleksey V Zapparov
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: Utility-belt to build form data request bodies. Provides support for
|
|
14
13
|
`application/x-www-form-urlencoded` and `multipart/form-data` types.
|
|
@@ -18,19 +17,9 @@ executables: []
|
|
|
18
17
|
extensions: []
|
|
19
18
|
extra_rdoc_files: []
|
|
20
19
|
files:
|
|
21
|
-
-
|
|
22
|
-
- ".gitignore"
|
|
23
|
-
- ".rspec"
|
|
24
|
-
- ".rubocop.yml"
|
|
25
|
-
- ".travis.yml"
|
|
26
|
-
- ".yardopts"
|
|
27
|
-
- CHANGES.md
|
|
28
|
-
- Gemfile
|
|
29
|
-
- Guardfile
|
|
20
|
+
- CHANGELOG.md
|
|
30
21
|
- LICENSE.txt
|
|
31
22
|
- README.md
|
|
32
|
-
- Rakefile
|
|
33
|
-
- appveyor.yml
|
|
34
23
|
- http-form_data.gemspec
|
|
35
24
|
- lib/http/form_data.rb
|
|
36
25
|
- lib/http/form_data/composite_io.rb
|
|
@@ -41,21 +30,25 @@ files:
|
|
|
41
30
|
- lib/http/form_data/readable.rb
|
|
42
31
|
- lib/http/form_data/urlencoded.rb
|
|
43
32
|
- lib/http/form_data/version.rb
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
|
|
54
|
-
homepage: https://github.com/httprb/form_data.rb
|
|
33
|
+
- sig/http/form_data.rbs
|
|
34
|
+
- sig/http/form_data/composite_io.rbs
|
|
35
|
+
- sig/http/form_data/file.rbs
|
|
36
|
+
- sig/http/form_data/multipart.rbs
|
|
37
|
+
- sig/http/form_data/multipart/param.rbs
|
|
38
|
+
- sig/http/form_data/part.rbs
|
|
39
|
+
- sig/http/form_data/readable.rbs
|
|
40
|
+
- sig/http/form_data/urlencoded.rbs
|
|
41
|
+
- sig/http/form_data/version.rbs
|
|
42
|
+
homepage: https://github.com/httprb/form_data
|
|
55
43
|
licenses:
|
|
56
44
|
- MIT
|
|
57
|
-
metadata:
|
|
58
|
-
|
|
45
|
+
metadata:
|
|
46
|
+
homepage_uri: https://github.com/httprb/form_data
|
|
47
|
+
source_code_uri: https://github.com/httprb/form_data/tree/v3.0.0
|
|
48
|
+
bug_tracker_uri: https://github.com/httprb/form_data/issues
|
|
49
|
+
changelog_uri: https://github.com/httprb/form_data/blob/v3.0.0/CHANGELOG.md
|
|
50
|
+
documentation_uri: https://www.rubydoc.info/gems/http-form_data/3.0.0
|
|
51
|
+
rubygems_mfa_required: 'true'
|
|
59
52
|
rdoc_options: []
|
|
60
53
|
require_paths:
|
|
61
54
|
- lib
|
|
@@ -63,26 +56,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
63
56
|
requirements:
|
|
64
57
|
- - ">="
|
|
65
58
|
- !ruby/object:Gem::Version
|
|
66
|
-
version: '
|
|
59
|
+
version: '3.2'
|
|
67
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
61
|
requirements:
|
|
69
62
|
- - ">="
|
|
70
63
|
- !ruby/object:Gem::Version
|
|
71
64
|
version: '0'
|
|
72
65
|
requirements: []
|
|
73
|
-
|
|
74
|
-
rubygems_version: 2.7.6.2
|
|
75
|
-
signing_key:
|
|
66
|
+
rubygems_version: 4.0.3
|
|
76
67
|
specification_version: 4
|
|
77
|
-
summary:
|
|
78
|
-
test_files:
|
|
79
|
-
- spec/fixtures/expected-multipart-body.tpl
|
|
80
|
-
- spec/fixtures/the-http-gem.info
|
|
81
|
-
- spec/lib/http/form_data/composite_io_spec.rb
|
|
82
|
-
- spec/lib/http/form_data/file_spec.rb
|
|
83
|
-
- spec/lib/http/form_data/multipart_spec.rb
|
|
84
|
-
- spec/lib/http/form_data/part_spec.rb
|
|
85
|
-
- spec/lib/http/form_data/urlencoded_spec.rb
|
|
86
|
-
- spec/lib/http/form_data_spec.rb
|
|
87
|
-
- spec/spec_helper.rb
|
|
88
|
-
- spec/support/fixtures_helper.rb
|
|
68
|
+
summary: Build form data request bodies
|
|
69
|
+
test_files: []
|
data/.editorconfig
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
AllCops:
|
|
2
|
-
DisplayCopNames: true
|
|
3
|
-
TargetRubyVersion: 2.4
|
|
4
|
-
|
|
5
|
-
## Metrics #####################################################################
|
|
6
|
-
|
|
7
|
-
Metrics/BlockLength:
|
|
8
|
-
Exclude:
|
|
9
|
-
- "Guardfile"
|
|
10
|
-
- "spec/**/*"
|
|
11
|
-
|
|
12
|
-
Metrics/MethodLength:
|
|
13
|
-
CountComments: false
|
|
14
|
-
Max: 15
|
|
15
|
-
|
|
16
|
-
## Styles ######################################################################
|
|
17
|
-
|
|
18
|
-
Style/AlignParameters:
|
|
19
|
-
EnforcedStyle: with_fixed_indentation
|
|
20
|
-
|
|
21
|
-
Style/BracesAroundHashParameters:
|
|
22
|
-
Enabled: false
|
|
23
|
-
|
|
24
|
-
Style/EmptyLineBetweenDefs:
|
|
25
|
-
AllowAdjacentOneLineDefs: true
|
|
26
|
-
|
|
27
|
-
Style/Encoding:
|
|
28
|
-
EnforcedStyle: when_needed
|
|
29
|
-
|
|
30
|
-
Style/HashSyntax:
|
|
31
|
-
EnforcedStyle: hash_rockets
|
|
32
|
-
|
|
33
|
-
Style/IndentHash:
|
|
34
|
-
EnforcedStyle: consistent
|
|
35
|
-
|
|
36
|
-
Style/IndentArray:
|
|
37
|
-
EnforcedStyle: consistent
|
|
38
|
-
|
|
39
|
-
# New lambda syntax is as ugly to me as new syntax of Hash.
|
|
40
|
-
Style/Lambda:
|
|
41
|
-
Enabled: false
|
|
42
|
-
|
|
43
|
-
Style/MultilineOperationIndentation:
|
|
44
|
-
EnforcedStyle: indented
|
|
45
|
-
|
|
46
|
-
Style/StringLiterals:
|
|
47
|
-
EnforcedStyle: double_quotes
|
|
48
|
-
|
|
49
|
-
Style/EmptyCaseCondition:
|
|
50
|
-
Enabled: false
|
|
51
|
-
|
|
52
|
-
# Not all trivial readers/writers can be defined with attr_* methods
|
|
53
|
-
#
|
|
54
|
-
# class Example < SimpleDelegator
|
|
55
|
-
# def __getobj__
|
|
56
|
-
# @obj
|
|
57
|
-
# end
|
|
58
|
-
#
|
|
59
|
-
# def __setobj__(obj)
|
|
60
|
-
# @obj = obj
|
|
61
|
-
# end
|
|
62
|
-
# end
|
|
63
|
-
Style/TrivialAccessors:
|
|
64
|
-
Enabled: false
|
data/.travis.yml
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
sudo: false
|
|
3
|
-
|
|
4
|
-
cache: bundler
|
|
5
|
-
|
|
6
|
-
before_install:
|
|
7
|
-
- gem update --system
|
|
8
|
-
- gem --version
|
|
9
|
-
- gem install bundler --no-document
|
|
10
|
-
- bundle --version
|
|
11
|
-
|
|
12
|
-
install: bundle install --without development doc
|
|
13
|
-
|
|
14
|
-
script: bundle exec rake
|
|
15
|
-
|
|
16
|
-
env: JRUBY_OPTS="$JRUBY_OPTS --debug"
|
|
17
|
-
|
|
18
|
-
rvm:
|
|
19
|
-
# Include JRuby first because it takes the longest
|
|
20
|
-
- jruby-9.1.13.0
|
|
21
|
-
- 2.4
|
|
22
|
-
- 2.5
|
|
23
|
-
- 2.6
|
|
24
|
-
- 2.7
|
|
25
|
-
|
|
26
|
-
matrix:
|
|
27
|
-
fast_finish: true
|
|
28
|
-
include:
|
|
29
|
-
- rvm: 2.7
|
|
30
|
-
env: SUITE="rubocop"
|
|
31
|
-
|
|
32
|
-
branches:
|
|
33
|
-
only:
|
|
34
|
-
- master
|
data/.yardopts
DELETED
data/CHANGES.md
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
## 2.3.0 (2020-03-08)
|
|
2
|
-
|
|
3
|
-
* [#29](https://github.com/httprb/form_data/pull/29)
|
|
4
|
-
Enhance HTTP::FormData::Urlencoded with per-instance encoder.
|
|
5
|
-
[@summera][]
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
## 2.2.0 (2020-01-09)
|
|
9
|
-
|
|
10
|
-
* [#28](https://github.com/httprb/form_data/pull/28)
|
|
11
|
-
Ruby 2.7 compatibility.
|
|
12
|
-
[@janko][]
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
## 2.1.1 (2018-06-01)
|
|
16
|
-
|
|
17
|
-
* [#23](https://github.com/httprb/form_data/pull/23)
|
|
18
|
-
Allow override urlencoded form data encoder.
|
|
19
|
-
[@FabienChaynes][]
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## 2.1.0 (2018-03-05)
|
|
23
|
-
|
|
24
|
-
* [#21](https://github.com/httprb/form_data/pull/21)
|
|
25
|
-
Rewind content at the end of `Readable#to_s`.
|
|
26
|
-
[@janko-m][]
|
|
27
|
-
|
|
28
|
-
* [#19](https://github.com/httprb/form_data/pull/19)
|
|
29
|
-
Fix buffer encoding.
|
|
30
|
-
[@HoneyryderChuck][]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## 2.0.0 (2017-10-01)
|
|
34
|
-
|
|
35
|
-
* [#17](https://github.com/httprb/form_data/pull/17)
|
|
36
|
-
Add CRLF character to end of multipart body.
|
|
37
|
-
[@mhickman][]
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
## 2.0.0.pre2 (2017-05-11)
|
|
41
|
-
|
|
42
|
-
* [#14](https://github.com/httprb/form_data/pull/14)
|
|
43
|
-
Enable streaming for urlencoded form data.
|
|
44
|
-
[@janko-m][]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
## 2.0.0.pre1 (2017-05-10)
|
|
48
|
-
|
|
49
|
-
* [#12](https://github.com/httprb/form_data.rb/pull/12)
|
|
50
|
-
Enable form data streaming.
|
|
51
|
-
[@janko-m][]
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
## 1.0.2 (2017-05-08)
|
|
55
|
-
|
|
56
|
-
* [#5](https://github.com/httprb/form_data.rb/issues/5)
|
|
57
|
-
Allow setting Content-Type non-file parts
|
|
58
|
-
[@abotalov][]
|
|
59
|
-
|
|
60
|
-
* [#6](https://github.com/httprb/form_data.rb/issues/6)
|
|
61
|
-
Creation of file parts without filename
|
|
62
|
-
[@abotalov][]
|
|
63
|
-
|
|
64
|
-
* [#11](https://github.com/httprb/form_data.rb/pull/11)
|
|
65
|
-
Deprecate `HTTP::FormData::File#mime_type`. Use `#content_type` instead.
|
|
66
|
-
[@ixti][]
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
## 1.0.1 (2015-03-31)
|
|
70
|
-
|
|
71
|
-
* Fix usage of URI module.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
## 1.0.0 (2015-01-04)
|
|
75
|
-
|
|
76
|
-
* Gem renamed to `http-form_data` as `FormData` is not top-level citizen
|
|
77
|
-
anymore: `FormData -> HTTP::FormData`.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
## 0.1.0 (2015-01-02)
|
|
81
|
-
|
|
82
|
-
* Move repo under `httprb` organization on GitHub.
|
|
83
|
-
* Add `nil` support to `FormData#ensure_hash`.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
## 0.0.1 (2014-12-15)
|
|
87
|
-
|
|
88
|
-
* First release ever!
|
|
89
|
-
|
|
90
|
-
[@ixti]: https://github.com/ixti
|
|
91
|
-
[@abotalov]: https://github.com/abotalov
|
|
92
|
-
[@janko-m]: https://github.com/janko-m
|
|
93
|
-
[@mhickman]: https://github.com/mhickman
|
|
94
|
-
[@HoneyryderChuck]: https://github.com/HoneyryderChuck
|
|
95
|
-
[@FabienChaynes]: https://github.com/FabienChaynes
|
|
96
|
-
[@summera]: https://github.com/summera
|
data/Gemfile
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
source "https://rubygems.org"
|
|
4
|
-
|
|
5
|
-
gem "rake"
|
|
6
|
-
|
|
7
|
-
group :development do
|
|
8
|
-
gem "guard"
|
|
9
|
-
gem "guard-rspec", :require => false
|
|
10
|
-
gem "pry"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
group :test do
|
|
14
|
-
gem "coveralls"
|
|
15
|
-
gem "rspec", "~> 3.1"
|
|
16
|
-
gem "rubocop", "= 0.48.1"
|
|
17
|
-
gem "simplecov", ">= 0.9"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
group :doc do
|
|
21
|
-
gem "redcarpet", :platform => :mri
|
|
22
|
-
gem "yard"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Specify your gem's dependencies in form_data.gemspec
|
|
26
|
-
gemspec
|
data/Guardfile
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
guard :rspec, :cmd => "bundle exec rspec" do
|
|
4
|
-
require "guard/rspec/dsl"
|
|
5
|
-
dsl = Guard::RSpec::Dsl.new(self)
|
|
6
|
-
|
|
7
|
-
# RSpec files
|
|
8
|
-
rspec = dsl.rspec
|
|
9
|
-
watch(rspec.spec_helper) { rspec.spec_dir }
|
|
10
|
-
watch(rspec.spec_support) { rspec.spec_dir }
|
|
11
|
-
watch(rspec.spec_files)
|
|
12
|
-
|
|
13
|
-
# Ruby files
|
|
14
|
-
ruby = dsl.ruby
|
|
15
|
-
dsl.watch_spec_files_for(ruby.lib_files)
|
|
16
|
-
end
|
data/Rakefile
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/gem_tasks"
|
|
4
|
-
|
|
5
|
-
require "rspec/core/rake_task"
|
|
6
|
-
RSpec::Core::RakeTask.new
|
|
7
|
-
|
|
8
|
-
begin
|
|
9
|
-
require "rubocop/rake_task"
|
|
10
|
-
RuboCop::RakeTask.new
|
|
11
|
-
rescue LoadError
|
|
12
|
-
task :rubocop do
|
|
13
|
-
$stderr.puts "RuboCop is disabled"
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
if ENV["CI"].nil?
|
|
18
|
-
task :default => %i[spec rubocop]
|
|
19
|
-
else
|
|
20
|
-
case ENV["SUITE"]
|
|
21
|
-
when "rubocop" then task :default => :rubocop
|
|
22
|
-
else task :default => :spec
|
|
23
|
-
end
|
|
24
|
-
end
|
data/appveyor.yml
DELETED
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
The HTTP Gem is an easy-to-use client library for making requests from Ruby.
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe HTTP::FormData::CompositeIO do
|
|
4
|
-
subject(:composite_io) { HTTP::FormData::CompositeIO.new(ios) }
|
|
5
|
-
|
|
6
|
-
let(:ios) { ["Hello", " ", "", "world", "!"].map { |s| StringIO.new(s) } }
|
|
7
|
-
|
|
8
|
-
describe "#initialize" do
|
|
9
|
-
it "accepts IOs and strings" do
|
|
10
|
-
io = HTTP::FormData::CompositeIO.new(["Hello ", StringIO.new("world!")])
|
|
11
|
-
expect(io.read).to eq "Hello world!"
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "fails if an IO is neither a String nor an IO" do
|
|
15
|
-
expect { HTTP::FormData::CompositeIO.new %i[hello world] }
|
|
16
|
-
.to raise_error(ArgumentError)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
describe "#read" do
|
|
21
|
-
it "reads all data" do
|
|
22
|
-
expect(composite_io.read).to eq "Hello world!"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "reads partial data" do
|
|
26
|
-
expect(composite_io.read(3)).to eq "Hel"
|
|
27
|
-
expect(composite_io.read(2)).to eq "lo"
|
|
28
|
-
expect(composite_io.read(1)).to eq " "
|
|
29
|
-
expect(composite_io.read(6)).to eq "world!"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "returns empty string when no data was retrieved" do
|
|
33
|
-
composite_io.read
|
|
34
|
-
expect(composite_io.read).to eq ""
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "returns nil when no partial data was retrieved" do
|
|
38
|
-
composite_io.read
|
|
39
|
-
expect(composite_io.read(3)).to eq nil
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "reads partial data with a buffer" do
|
|
43
|
-
outbuf = String.new
|
|
44
|
-
expect(composite_io.read(3, outbuf)).to eq "Hel"
|
|
45
|
-
expect(composite_io.read(2, outbuf)).to eq "lo"
|
|
46
|
-
expect(composite_io.read(1, outbuf)).to eq " "
|
|
47
|
-
expect(composite_io.read(6, outbuf)).to eq "world!"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "fills the buffer with retrieved content" do
|
|
51
|
-
outbuf = String.new
|
|
52
|
-
composite_io.read(3, outbuf)
|
|
53
|
-
expect(outbuf).to eq "Hel"
|
|
54
|
-
composite_io.read(2, outbuf)
|
|
55
|
-
expect(outbuf).to eq "lo"
|
|
56
|
-
composite_io.read(1, outbuf)
|
|
57
|
-
expect(outbuf).to eq " "
|
|
58
|
-
composite_io.read(6, outbuf)
|
|
59
|
-
expect(outbuf).to eq "world!"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "returns nil when no partial data was retrieved with a buffer" do
|
|
63
|
-
outbuf = String.new("content")
|
|
64
|
-
composite_io.read
|
|
65
|
-
expect(composite_io.read(3, outbuf)).to eq nil
|
|
66
|
-
expect(outbuf).to eq ""
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "returns data in binary encoding" do
|
|
70
|
-
io = HTTP::FormData::CompositeIO.new(%w[Janko Marohnić])
|
|
71
|
-
|
|
72
|
-
expect(io.read(5).encoding).to eq Encoding::BINARY
|
|
73
|
-
expect(io.read(9).encoding).to eq Encoding::BINARY
|
|
74
|
-
|
|
75
|
-
io.rewind
|
|
76
|
-
expect(io.read.encoding).to eq Encoding::BINARY
|
|
77
|
-
expect(io.read.encoding).to eq Encoding::BINARY
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "reads data in bytes" do
|
|
81
|
-
emoji = "😃"
|
|
82
|
-
io = HTTP::FormData::CompositeIO.new([emoji])
|
|
83
|
-
|
|
84
|
-
expect(io.read(1)).to eq emoji.b[0]
|
|
85
|
-
expect(io.read(1)).to eq emoji.b[1]
|
|
86
|
-
expect(io.read(1)).to eq emoji.b[2]
|
|
87
|
-
expect(io.read(1)).to eq emoji.b[3]
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
describe "#rewind" do
|
|
92
|
-
it "rewinds all IOs" do
|
|
93
|
-
composite_io.read
|
|
94
|
-
composite_io.rewind
|
|
95
|
-
expect(composite_io.read).to eq "Hello world!"
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
describe "#size" do
|
|
100
|
-
it "returns sum of all IO sizes" do
|
|
101
|
-
expect(composite_io.size).to eq 12
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it "returns 0 when there are no IOs" do
|
|
105
|
-
empty_composite_io = HTTP::FormData::CompositeIO.new []
|
|
106
|
-
expect(empty_composite_io.size).to eq 0
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
end
|