Sha256: c4f64dd8f09dd30144e4c7c54b242ab860c027028b1268c2fb9eb2429a32f67b

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    module Compression
      module Deflate
        def self.load_dependencies(klass)
          require "stringio"
          require "zlib"
          klass.plugin(:"compression/gzip")
        end

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

        module Deflater
          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 deflater
          Deflater
        end

        def inflater(bytesize)
          GZIP::Inflater.new(bytesize)
        end
      end
    end
    register_plugin :"compression/deflate", Compression::Deflate
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
httpx-0.11.3 lib/httpx/plugins/compression/deflate.rb
httpx-0.11.2 lib/httpx/plugins/compression/deflate.rb
httpx-0.11.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.11.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.10.2 lib/httpx/plugins/compression/deflate.rb
httpx-0.10.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.10.0 lib/httpx/plugins/compression/deflate.rb