Class: Isomorfeus::Transport::CompressorRack::GzipStream
- Inherits:
-
Object
- Object
- Isomorfeus::Transport::CompressorRack::GzipStream
- Defined in:
- lib/isomorfeus/transport/compressor_rack.rb
Constant Summary collapse
- BUFFER_LENGTH =
128 * 1_024
Instance Method Summary collapse
- #close ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(body, mtime, sync) ⇒ GzipStream
constructor
A new instance of GzipStream.
- #write(data) ⇒ Object
Constructor Details
#initialize(body, mtime, sync) ⇒ GzipStream
Returns a new instance of GzipStream.
91 92 93 94 95 |
# File 'lib/isomorfeus/transport/compressor_rack.rb', line 91 def initialize(body, mtime, sync) @body = body @mtime = mtime @sync = sync end |
Instance Method Details
#close ⇒ Object
122 123 124 |
# File 'lib/isomorfeus/transport/compressor_rack.rb', line 122 def close @body.close if @body.respond_to?(:close) end |
#each(&block) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/isomorfeus/transport/compressor_rack.rb', line 97 def each(&block) @writer = block gzip = ::Zlib::GzipWriter.new(self) gzip.mtime = @mtime if @mtime if @body.is_a? ::File while part = @body.read(BUFFER_LENGTH) gzip.write(part) gzip.flush if @sync end else @body.each do |part| next if part.empty? gzip.write(part) gzip.flush if @sync end end ensure gzip.close end |
#write(data) ⇒ Object
118 119 120 |
# File 'lib/isomorfeus/transport/compressor_rack.rb', line 118 def write(data) @writer.call(data) end |