Class: HTTP::Features::AutoDeflate::CompressedBody

Inherits:
Request::Body
  • Object
show all
Defined in:
lib/http/features/auto_deflate.rb,
sig/http.rbs

Overview

Base class for compressed request body wrappers

Direct Known Subclasses

DeflatedBody, GzippedBody

Instance Attribute Summary

Attributes inherited from Request::Body

#source

Instance Method Summary collapse

Methods inherited from Request::Body

#==, #empty?, #loggable?, #rewind, #validate_source_type!

Constructor Details

#initialize(uncompressed_body) ⇒ CompressedBody

Initializes a compressed body wrapper

Examples:

CompressedBody.new(uncompressed_body)

Parameters:



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

#compressvoid

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

Yields:

Yield Parameters:

  • arg0 (String)

Yield Returns:

  • (void)


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

#eachself #eachEnumerator[String, self]

Yields each chunk of compressed data

Examples:

compressed_body.each { |chunk| io.write(chunk) }

Overloads:

  • #eachself

    Returns:

    • (self)
  • #eachEnumerator[String, self]

    Returns:

    • (Enumerator[String, self])

Yields:

Yield Parameters:

  • arg0 (String)

Yield Returns:

  • (void)

Returns:

  • (self, Enumerator)


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

#sizeInteger

Returns the size of the compressed body

Examples:

compressed_body.size

Returns:

  • (Integer)


118
119
120
121
# File 'lib/http/features/auto_deflate.rb', line 118

def size
  compress_all! unless @compressed
  @compressed.size
end