Sha256: d59feb6d6dbed7dc2b314d7dbe60fe4d2c3a9d19fccde2c1518b3593e9fdcf3a

Contents?: true

Size: 832 Bytes

Versions: 20

Compression:

Stored size: 832 Bytes

Contents

# frozen_string_literal: true

require "zlib"
require_relative "utils/deflater"

module HTTPX
  module Transcoder
    module Deflate
      class Deflater < Transcoder::Deflater
        def deflate(chunk)
          @deflater ||= Zlib::Deflate.new

          if chunk.nil?
            unless @deflater.closed?
              last = @deflater.finish
              @deflater.close
              last.empty? ? nil : last
            end
          else
            @deflater.deflate(chunk)
          end
        end
      end

      module_function

      def encode(body)
        Deflater.new(body)
      end

      def decode(response, bytesize: nil)
        bytesize ||= response.headers.key?("content-length") ? response.headers["content-length"].to_i : Float::INFINITY
        GZIP::Inflater.new(bytesize)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
httpx-1.3.4 lib/httpx/transcoder/deflate.rb
httpx-1.3.3 lib/httpx/transcoder/deflate.rb
httpx-1.3.2 lib/httpx/transcoder/deflate.rb
httpx-1.3.1 lib/httpx/transcoder/deflate.rb
httpx-1.3.0 lib/httpx/transcoder/deflate.rb
httpx-1.2.6 lib/httpx/transcoder/deflate.rb
httpx-1.2.4 lib/httpx/transcoder/deflate.rb
httpx-1.2.3 lib/httpx/transcoder/deflate.rb
httpx-1.2.2 lib/httpx/transcoder/deflate.rb
httpx-1.2.1 lib/httpx/transcoder/deflate.rb
httpx-1.2.0 lib/httpx/transcoder/deflate.rb
httpx-1.1.5 lib/httpx/transcoder/deflate.rb
httpx-1.1.4 lib/httpx/transcoder/deflate.rb
httpx-1.1.3 lib/httpx/transcoder/deflate.rb
httpx-1.1.2 lib/httpx/transcoder/deflate.rb
httpx-1.1.1 lib/httpx/transcoder/deflate.rb
httpx-1.1.0 lib/httpx/transcoder/deflate.rb
httpx-1.0.2 lib/httpx/transcoder/deflate.rb
httpx-1.0.1 lib/httpx/transcoder/deflate.rb
httpx-1.0.0 lib/httpx/transcoder/deflate.rb