Class: Aws::Plugins::RequestCompression::CompressionHandler::GzipIO Private

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-core/plugins/request_compression.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ GzipIO

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of GzipIO.



171
172
173
174
175
# File 'lib/aws-sdk-core/plugins/request_compression.rb', line 171

def initialize(body)
  @body = body
  @buffer = ChunkBuffer.new
  @gzip_writer = Zlib::GzipWriter.new(@buffer)
end

Instance Method Details

#read(length, buff = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/aws-sdk-core/plugins/request_compression.rb', line 177

def read(length, buff = nil)
  if @gzip_writer.closed?
    # an empty string to signify an end as
    # there will be nothing remaining to be read
    StringIO.new('').read(length, buff)
    return
  end

  chunk = @body.read(length)
  if !chunk || chunk.empty?
    # closing the writer will write one last chunk
    # with a trailer (to be read from the @buffer)
    @gzip_writer.close
  else
    # flush happens first to ensure that header fields
    # are being sent over since write will override
    @gzip_writer.flush
    @gzip_writer.write(chunk)
  end

  StringIO.new(@buffer.last_chunk).read(length, buff)
end