Sha256: 8a2da4dd2e6b5ef3e9d743a7871463104a7049d065808dfa581077c8ba51d1e2

Contents?: true

Size: 1.15 KB

Versions: 45

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

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

        def self.configure(klass)
          klass.plugin(:"compression/gzip")
          klass.default_options.encodings.register "deflate", self
        end

        module Deflater
          module_function

          def deflate(raw, buffer = "".b, chunk_size: 16_384)
            deflater = Zlib::Deflate.new
            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?
            buffer
          ensure
            deflater.close if deflater
          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

45 entries across 45 versions & 1 rubygems

Version Path
httpx-0.19.2 lib/httpx/plugins/compression/deflate.rb
httpx-0.19.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.19.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.18.7 lib/httpx/plugins/compression/deflate.rb
httpx-0.18.6 lib/httpx/plugins/compression/deflate.rb
httpx-0.18.5 lib/httpx/plugins/compression/deflate.rb
httpx-0.18.4 lib/httpx/plugins/compression/deflate.rb
httpx-0.18.3 lib/httpx/plugins/compression/deflate.rb
httpx-0.18.2 lib/httpx/plugins/compression/deflate.rb
httpx-0.18.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.18.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.17.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.16.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.16.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.15.4 lib/httpx/plugins/compression/deflate.rb
httpx-0.15.3 lib/httpx/plugins/compression/deflate.rb
httpx-0.15.2 lib/httpx/plugins/compression/deflate.rb
httpx-0.15.1 lib/httpx/plugins/compression/deflate.rb
httpx-0.15.0 lib/httpx/plugins/compression/deflate.rb
httpx-0.14.5 lib/httpx/plugins/compression/deflate.rb