Class: Archive::Tar::Minitar::Writer::BoundedStream
- Inherits:
-
RestrictedStream
- Object
- RestrictedStream
- Archive::Tar::Minitar::Writer::BoundedStream
- Defined in:
- lib/archive/tar/minitar.rb
Overview
A RestrictedStream that also has a size limit.
Defined Under Namespace
Classes: FileOverflow
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
The maximum number of bytes that may be written to this data stream.
-
#written ⇒ Object
readonly
The current total number of bytes written to this data stream.
Instance Method Summary collapse
-
#initialize(io, limit) ⇒ BoundedStream
constructor
A new instance of BoundedStream.
- #write(data) ⇒ Object
Constructor Details
#initialize(io, limit) ⇒ BoundedStream
Returns a new instance of BoundedStream.
278 279 280 281 282 |
# File 'lib/archive/tar/minitar.rb', line 278 def initialize(io, limit) @io = io @limit = limit @written = 0 end |
Instance Attribute Details
#limit ⇒ Object (readonly)
The maximum number of bytes that may be written to this data stream.
274 275 276 |
# File 'lib/archive/tar/minitar.rb', line 274 def limit @limit end |
#written ⇒ Object (readonly)
The current total number of bytes written to this data stream.
276 277 278 |
# File 'lib/archive/tar/minitar.rb', line 276 def written @written end |
Instance Method Details
#write(data) ⇒ Object
284 285 286 287 288 289 |
# File 'lib/archive/tar/minitar.rb', line 284 def write(data) raise FileOverflow if (data.size + @written) > @limit @io.write(data) @written += data.size data.size end |