Class: HTTP::Features::AutoDeflate::GzippedBody

Inherits:
CompressedBody show all
Defined in:
lib/http/features/auto_deflate.rb

Overview

Gzip-compressed request body wrapper

Defined Under Namespace

Classes: BlockIO

Instance Attribute Summary

Attributes inherited from Request::Body

#source

Instance Method Summary collapse

Methods inherited from CompressedBody

#each, #initialize, #size

Methods inherited from Request::Body

#==, #each, #empty?, #initialize, #loggable?, #size

Constructor Details

This class inherits a constructor from HTTP::Features::AutoDeflate::CompressedBody

Instance Method Details

#compress(&block) ⇒ nil

Compresses data using gzip

Examples:

gzipped_body.compress { |data| io.write(data) }

Returns:

  • (nil)


174
175
176
177
178
179
# File 'lib/http/features/auto_deflate.rb', line 174

def compress(&block)
  gzip = Zlib::GzipWriter.new(BlockIO.new(block))
  @body.each { |chunk| gzip.write(chunk) }
ensure
  gzip.finish
end