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.
272 273 274 275 276 |
# File 'lib/archive/tar/minitar.rb', line 272 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.
268 269 270 |
# File 'lib/archive/tar/minitar.rb', line 268 def limit @limit end |
#written ⇒ Object (readonly)
The current total number of bytes written to this data stream.
270 271 272 |
# File 'lib/archive/tar/minitar.rb', line 270 def written @written end |
Instance Method Details
#write(data) ⇒ Object
278 279 280 281 282 283 |
# File 'lib/archive/tar/minitar.rb', line 278 def write(data) raise FileOverflow if (data.size + @written) > @limit @io.write(data) @written += data.size data.size end |