Class: Agouti::Rack::PackageLimiter::GzipTruncatedStream
- Inherits:
-
Rack::Deflater::GzipStream
- Object
- Rack::Deflater::GzipStream
- Agouti::Rack::PackageLimiter::GzipTruncatedStream
- Defined in:
- lib/agouti/rack/package_limiter.rb
Overview
Public: class responsible for truncating the gzip stream to a given number of bytes.
Instance Method Summary (collapse)
-
- (GzipTruncatedStream) initialize(body, mtime, byte_limit)
constructor
Public: Constructor.
-
- (Object) write(data)
Public: Writes data to stream.
Constructor Details
- (GzipTruncatedStream) initialize(body, mtime, byte_limit)
Public: Constructor.
body - response body. mtime - last-modified time. byte_limit - byte limit.
Returns an instance of Agouti::Rack::PackageLimiter::GzipTruncatedStream.
106 107 108 109 110 |
# File 'lib/agouti/rack/package_limiter.rb', line 106 def initialize body, mtime, byte_limit super body, mtime @byte_limit = byte_limit @total_sent_bytes = 0 end |
Instance Method Details
- (Object) write(data)
Public: Writes data to stream.
data - data.
If total sent bytes reaches bytes limit, data is sliced.
117 118 119 120 121 122 123 124 |
# File 'lib/agouti/rack/package_limiter.rb', line 117 def write(data) if @total_sent_bytes + data.bytesize > @byte_limit data = data.byteslice(0, @byte_limit - @total_sent_bytes) end @total_sent_bytes += data.bytesize @writer.call(data) end |