Class: Gem::Package::TarWriter::BoundedStream
- Inherits:
-
Object
- Object
- Gem::Package::TarWriter::BoundedStream
- Defined in:
- lib/rubygems/package/tar_writer.rb
Overview
IO wrapper that allows writing a limited amount of data
Instance Attribute Summary (collapse)
-
- (Object) limit
readonly
Maximum number of bytes that can be written.
-
- (Object) written
readonly
Number of bytes written.
Instance Method Summary (collapse)
-
- (BoundedStream) initialize(io, limit)
constructor
Wraps io and allows up to limit bytes to be written.
-
- (Object) write(data)
Writes data onto the IO, raising a FileOverflow exception if the number of bytes will be more than #limit.
Constructor Details
- (BoundedStream) initialize(io, limit)
Wraps io and allows up to limit bytes to be written
32 33 34 35 36 |
# File 'lib/rubygems/package/tar_writer.rb', line 32 def initialize(io, limit) @io = io @limit = limit @written = 0 end |
Instance Attribute Details
- (Object) limit (readonly)
Maximum number of bytes that can be written
22 23 24 |
# File 'lib/rubygems/package/tar_writer.rb', line 22 def limit @limit end |
- (Object) written (readonly)
Number of bytes written
27 28 29 |
# File 'lib/rubygems/package/tar_writer.rb', line 27 def written @written end |
Instance Method Details
- (Object) write(data)
Writes data onto the IO, raising a FileOverflow exception if the number of bytes will be more than #limit
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rubygems/package/tar_writer.rb', line 42 def write(data) # XXX MACRUBY mainly because our File.open won't honor 'b'. data = data.force_encoding('BINARY') if data.size + @written > @limit raise FileOverflow, "You tried to feed more data than fits in the file." end @io.write data @written += data.size data.size end |