Sha256: 3875e4225de9b6c2e543e30aed07a3c3b1317513b0a3630b31c18bd34c969e90

Contents?: true

Size: 1.25 KB

Versions: 27

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    module Compression
      module Deflate
        def self.load_dependencies(*)
          require "stringio"
          require "zlib"
        end

        def self.configure(*)
          Compression.register "deflate", self
        end

        module Encoder
          module_function

          def deflate(raw, buffer, chunk_size:)
            deflater = Zlib::Deflate.new(Zlib::BEST_COMPRESSION,
                                         Zlib::MAX_WBITS,
                                         Zlib::MAX_MEM_LEVEL,
                                         Zlib::HUFFMAN_ONLY)
            while (chunk = raw.read(chunk_size))
              compressed = deflater.deflate(chunk)
              buffer << compressed
              yield compressed if block_given?
            end
            last = deflater.finish
            buffer << last
            yield last if block_given?
          ensure
            deflater.close
          end
        end

        module_function

        def encoder
          Encoder
        end

        def decoder
          Decoder.new(Zlib::Inflate.new(32 + Zlib::MAX_WBITS))
        end
      end
    end
    register_plugin :"compression/deflate", Compression::Deflate
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
httpx-0.9.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.8.2 lib/httpx/plugins/compression/deflate.rb
httpx-0.8.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.8.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.7.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.6.7 lib/httpx/plugins/compression/deflate.rb
httpx-0.6.6 lib/httpx/plugins/compression/deflate.rb
httpx-0.6.5 lib/httpx/plugins/compression/deflate.rb
httpx-0.6.4 lib/httpx/plugins/compression/deflate.rb
httpx-0.6.3 lib/httpx/plugins/compression/deflate.rb
httpx-0.6.2 lib/httpx/plugins/compression/deflate.rb
httpx-0.6.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.6.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.5.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.5.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.4.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.4.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.3.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.3.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.2.1 lib/httpx/plugins/compression/deflate.rb