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

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

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?

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

#each(&block) ⇒ self, Enumerator

Yields each chunk of compressed data

Examples:

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

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