Sha256: 4f72dc90bb2705c20370317754deb8d723cdf5854a30bb7df2cafa6382221ec2

Contents?: true

Size: 1.14 KB

Versions: 45

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    module Compression
      module Brotli
        class << self
          def load_dependencies(_klass)
            require "brotli"
          end

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

        module Deflater
          module_function

          def deflate(raw, buffer = "".b, chunk_size: 16_384)
            while (chunk = raw.read(chunk_size))
              compressed = ::Brotli.deflate(chunk)
              buffer << compressed
              yield compressed if block_given?
            end
            buffer
          end
        end

        class Inflater
          def initialize(bytesize)
            @bytesize = bytesize
          end

          def inflate(chunk)
            ::Brotli.inflate(chunk)
          end
        end

        module_function

        def deflater
          Deflater
        end

        def inflater(bytesize)
          Inflater.new(bytesize)
        end
      end
    end
    register_plugin :"compression/brotli", Compression::Brotli
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
httpx-0.22.5 lib/httpx/plugins/compression/brotli.rb
httpx-0.22.4 lib/httpx/plugins/compression/brotli.rb
httpx-0.22.3 lib/httpx/plugins/compression/brotli.rb
httpx-0.22.2 lib/httpx/plugins/compression/brotli.rb
httpx-0.22.1 lib/httpx/plugins/compression/brotli.rb
httpx-0.22.0 lib/httpx/plugins/compression/brotli.rb
httpx-0.21.1 lib/httpx/plugins/compression/brotli.rb
httpx-0.21.0 lib/httpx/plugins/compression/brotli.rb
httpx-0.20.5 lib/httpx/plugins/compression/brotli.rb
httpx-0.20.4 lib/httpx/plugins/compression/brotli.rb
httpx-0.20.3 lib/httpx/plugins/compression/brotli.rb
httpx-0.20.2 lib/httpx/plugins/compression/brotli.rb
httpx-0.20.1 lib/httpx/plugins/compression/brotli.rb
httpx-0.20.0 lib/httpx/plugins/compression/brotli.rb
httpx-0.19.8 lib/httpx/plugins/compression/brotli.rb
httpx-0.19.7 lib/httpx/plugins/compression/brotli.rb
httpx-0.19.6 lib/httpx/plugins/compression/brotli.rb
httpx-0.19.5 lib/httpx/plugins/compression/brotli.rb
httpx-0.19.4 lib/httpx/plugins/compression/brotli.rb
httpx-0.19.3 lib/httpx/plugins/compression/brotli.rb