Sha256: f3a8944e63b742afebbb855304fdbeb0f49bb3a4df7e27e1df2d4a3105c5db10

Contents?: true

Size: 1.06 KB

Versions: 16

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

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

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

        module Encoder
          module_function

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

        module BrotliWrapper
          module_function

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

          def close; end

          def finish
            ""
          end
        end

        module_function

        def encoder
          Encoder
        end

        def decoder
          Decoder.new(BrotliWrapper)
        end
      end
    end
    register_plugin :"compression/brotli", Compression::Brotli
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

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