Sha256: 06cff8f5c9bd5faf2a821ad07cd82dfcd42fbcd7733c2ade2cfe1c0c28cae75a

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    module Compression
      module Brotli
        class << self
          def load_dependencies(klass)
            require "brotli"
            klass.plugin(:compression)
          end

          def extra_options(options)
            options.merge(encodings: options.encodings.merge("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

13 entries across 13 versions & 1 rubygems

Version Path
httpx-0.24.7 lib/httpx/plugins/compression/brotli.rb
httpx-0.24.6 lib/httpx/plugins/compression/brotli.rb
httpx-0.24.5 lib/httpx/plugins/compression/brotli.rb
httpx-0.24.4 lib/httpx/plugins/compression/brotli.rb
httpx-0.24.3 lib/httpx/plugins/compression/brotli.rb
httpx-0.24.2 lib/httpx/plugins/compression/brotli.rb
httpx-0.24.1 lib/httpx/plugins/compression/brotli.rb
httpx-0.24.0 lib/httpx/plugins/compression/brotli.rb
httpx-0.23.4 lib/httpx/plugins/compression/brotli.rb
httpx-0.23.3 lib/httpx/plugins/compression/brotli.rb
httpx-0.23.2 lib/httpx/plugins/compression/brotli.rb
httpx-0.23.1 lib/httpx/plugins/compression/brotli.rb
httpx-0.23.0 lib/httpx/plugins/compression/brotli.rb