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