File tree 4 files changed +22
-5
lines changed
4 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -17,19 +17,28 @@ class Buffered < Readable
17
17
#
18
18
# @parameter body [String | Array(String) | Readable | nil] the body to wrap.
19
19
# @returns [Readable | nil] the wrapped body or nil if nil was given.
20
- def self . wrap ( body )
20
+ def self . for ( body )
21
21
if body . is_a? ( Readable )
22
22
return body
23
23
elsif body . is_a? ( Array )
24
24
return self . new ( body )
25
25
elsif body . is_a? ( String )
26
26
return self . new ( [ body ] )
27
27
elsif body
28
- return self . for ( body )
28
+ return self . read ( body )
29
29
end
30
30
end
31
31
32
- def self . for ( body )
32
+ # @deprecated Use {#for} instead.
33
+ def self . wrap ( body )
34
+ self . for ( body )
35
+ end
36
+
37
+ # Read the entire body into a buffered representation.
38
+ #
39
+ # @parameter body [Readable] the body to read.
40
+ # @returns [Buffered] the buffered body.
41
+ def self . read ( body )
33
42
chunks = [ ]
34
43
35
44
body . each do |chunk |
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ def call(stream)
66
66
# @returns [Buffered] The buffered body.
67
67
def finish
68
68
# Internally, this invokes `self.each` which then invokes `self.close`.
69
- Buffered . for ( self )
69
+ Buffered . read ( self )
70
70
end
71
71
72
72
# Enumerate all chunks until finished, then invoke `#close`.
Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ module HTTP
11
11
module Body
12
12
# A body which buffers all it's contents as it is `#read`.
13
13
class Rewindable < Wrapper
14
+ def self . for ( body )
15
+ if body . rewindable?
16
+ body
17
+ else
18
+ self . new ( body )
19
+ end
20
+ end
21
+
14
22
def initialize ( body )
15
23
super ( body )
16
24
Original file line number Diff line number Diff line change 14
14
let ( :sample ) { "The quick brown fox jumps over the lazy dog." }
15
15
let ( :chunks ) { [ sample ] * 1024 }
16
16
17
- let ( :body ) { Protocol ::HTTP ::Body ::Buffered . for ( chunks ) }
17
+ let ( :body ) { Protocol ::HTTP ::Body ::Buffered . new ( chunks ) }
18
18
let ( :deflate_body ) { Protocol ::HTTP ::Body ::Deflate . for ( body ) }
19
19
let ( :compressed_chunks ) { deflate_body . join . each_char . to_a }
20
20
let ( :compressed_body_chunks ) { compressed_chunks }
You can’t perform that action at this time.
0 commit comments