Sha256: a186863da2b12f67da110f715fc19605be8120b6b1ad4436a730965be21c66ec

Contents?: true

Size: 1.22 KB

Versions: 23

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require "forwardable"

module HTTPX
  module Plugins
    module Compression
      module GZIP
        def self.load_dependencies(*)
          require "zlib"
        end

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

        class Encoder
          def deflate(raw, buffer, chunk_size:)
            gzip = Zlib::GzipWriter.new(self)

            while (chunk = raw.read(chunk_size))
              gzip.write(chunk)
              gzip.flush
              compressed = compressed_chunk
              buffer << compressed
              yield compressed if block_given?
            end
          ensure
            gzip.close
          end

          private

          def write(chunk)
            @compressed_chunk = chunk
          end

          def compressed_chunk
            compressed = @compressed_chunk
            compressed
          ensure
            @compressed_chunk = nil
          end
        end

        module_function

        def encoder
          Encoder.new
        end

        def decoder
          Decoder.new(Zlib::Inflate.new(32 + Zlib::MAX_WBITS))
        end
      end
    end
    register_plugin :"compression/gzip", Compression::GZIP
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
httpx-0.7.0 lib/httpx/plugins/compression/gzip.rb
httpx-0.6.7 lib/httpx/plugins/compression/gzip.rb
httpx-0.6.6 lib/httpx/plugins/compression/gzip.rb
httpx-0.6.5 lib/httpx/plugins/compression/gzip.rb
httpx-0.6.4 lib/httpx/plugins/compression/gzip.rb
httpx-0.6.3 lib/httpx/plugins/compression/gzip.rb
httpx-0.6.2 lib/httpx/plugins/compression/gzip.rb
httpx-0.6.1 lib/httpx/plugins/compression/gzip.rb
httpx-0.6.0 lib/httpx/plugins/compression/gzip.rb
httpx-0.5.1 lib/httpx/plugins/compression/gzip.rb
httpx-0.5.0 lib/httpx/plugins/compression/gzip.rb
httpx-0.4.1 lib/httpx/plugins/compression/gzip.rb
httpx-0.4.0 lib/httpx/plugins/compression/gzip.rb
httpx-0.3.1 lib/httpx/plugins/compression/gzip.rb
httpx-0.3.0 lib/httpx/plugins/compression/gzip.rb
httpx-0.2.1 lib/httpx/plugins/compression/gzip.rb
httpx-0.2.0 lib/httpx/plugins/compression/gzip.rb
httpx-0.1.0 lib/httpx/plugins/compression/gzip.rb
httpx-0.0.5 lib/httpx/plugins/compression/gzip.rb
httpx-0.0.4 lib/httpx/plugins/compression/gzip.rb