module Webmachine::Resource::Encodings

This module implements standard Content-Encodings that you might want to use in your {Resource}. To use one, simply return it in the hash from {Callbacks#encodings_provided}.

Public Instance Methods

encode_deflate(data) click to toggle source

The ‘deflate’ encoding, which uses libz’s DEFLATE compression.

# File lib/webmachine/resource/encodings.rb, line 16
def encode_deflate(data)
  # The deflate options were borrowed from Rack and Mongrel1.
  Zlib::Deflate.deflate(data, Zlib::DEFAULT_COMPRESSION, -Zlib::MAX_WBITS, Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY)
end
encode_gzip(data) click to toggle source

The ‘gzip’ encoding, which uses GNU Zip (via libz). @note Because of the header/checksum requirements, gzip cannot

be used on streamed responses.
# File lib/webmachine/resource/encodings.rb, line 24
def encode_gzip(data)
  ''.tap do |out|
    Zlib::GzipWriter.wrap(StringIO.new(out)) { |gz| gz << data }
  end
end
encode_identity(data) click to toggle source

The ‘identity’ encoding, which does no compression.

# File lib/webmachine/resource/encodings.rb, line 11
def encode_identity(data)
  data
end