Class: HTTP::Features::AutoDeflate::CompressedBody
- Inherits:
-
Request::Body
- Object
- Request::Body
- HTTP::Features::AutoDeflate::CompressedBody
- Defined in:
- lib/http/features/auto_deflate.rb,
sig/http.rbs
Overview
Base class for compressed request body wrappers
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Request::Body
Instance Method Summary collapse
- #compress ⇒ void
-
#compress_all! ⇒ void
private
Compress all data to a tempfile.
-
#compressed_each {|arg0| ... } ⇒ void
private
Yield each chunk from compressed data.
-
#each {|arg0| ... } ⇒ self, Enumerator
Yields each chunk of compressed data.
-
#initialize(uncompressed_body) ⇒ CompressedBody
constructor
Initializes a compressed body wrapper.
-
#size ⇒ Integer
Returns the size of the compressed body.
Methods inherited from Request::Body
#==, #empty?, #loggable?, #rewind, #validate_source_type!
Constructor Details
#initialize(uncompressed_body) ⇒ CompressedBody
Initializes a compressed body wrapper
105 106 107 108 109 |
# File 'lib/http/features/auto_deflate.rb', line 105 def initialize(uncompressed_body) super(nil) @body = uncompressed_body @compressed = nil end |
Instance Method Details
#compress ⇒ void
This method returns an undefined value.
384 |
# File 'sig/http.rbs', line 384
def compress: () ?{ (String) -> void } -> void
|
#compress_all! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Compress all data to a tempfile
158 159 160 161 162 |
# File 'lib/http/features/auto_deflate.rb', line 158 def compress_all! @compressed = Tempfile.new("http-compressed_body", binmode: true) compress { |data| @compressed.write(data) } @compressed.rewind end |
#compressed_each {|arg0| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Yield each chunk from compressed data
147 148 149 150 151 152 153 |
# File 'lib/http/features/auto_deflate.rb', line 147 def compressed_each while (data = @compressed.read(Connection::BUFFER_SIZE)) yield data end ensure @compressed.close! end |
#each ⇒ self #each ⇒ Enumerator[String, self]
Yields each chunk of compressed data
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/http/features/auto_deflate.rb', line 130 def each(&block) return to_enum(:each) unless block if @compressed compressed_each(&block) else compress(&block) end self end |
#size ⇒ Integer
Returns the size of the compressed body
118 119 120 121 |
# File 'lib/http/features/auto_deflate.rb', line 118 def size compress_all! unless @compressed @compressed.size end |