Sha256: 071bd6b83a35b3ace00b254149b4c593e17d60fead70ac611fbd576bc1f5276d
Contents?: true
Size: 1.33 KB
Versions: 13
Compression:
Stored size: 1.33 KB
Contents
require 'zlib' require 'stringio' module Webmachine class Resource # 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}. module Encodings # The 'identity' encoding, which does no compression. def encode_identity(data) data end # The 'deflate' encoding, which uses libz's DEFLATE compression. def encode_deflate(data) # The deflate options were borrowed from Rack and Mongrel1. Zlib::Deflate.deflate(data, *[Zlib::DEFAULT_COMPRESSION, # drop the zlib header which causes both Safari and IE to choke -Zlib::MAX_WBITS, Zlib::DEF_MEM_LEVEL, Zlib::DEFAULT_STRATEGY ]) end # The 'gzip' encoding, which uses GNU Zip (via libz). # @note Because of the header/checksum requirements, gzip cannot # be used on streamed responses. def encode_gzip(data) "".tap do |out| Zlib::GzipWriter.wrap(StringIO.new(out)){|gz| gz << data } end end end # module Encodings end # class Resource end # module Webmachine
Version data entries
13 entries across 12 versions & 1 rubygems