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
- 
  
    
      #limit  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Maximum number of bytes that can be written.
 - 
  
    
      #written  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Number of bytes written.
 
Instance Method Summary collapse
- 
  
    
      #initialize(io, limit)  ⇒ BoundedStream 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Wraps
ioand allows up tolimitbytes to be written. - 
  
    
      #write(data)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Writes
dataonto the IO, raising a FileOverflow exception if the number of bytes will be more than #limit. 
Constructor Details
#initialize(io, limit) ⇒ BoundedStream
Wraps io and allows up to limit bytes to be written
      31 32 33 34 35  | 
    
      # File 'lib/rubygems/package/tar_writer.rb', line 31 def initialize(io, limit) @io = io @limit = limit @written = 0 end  | 
  
Instance Attribute Details
#limit ⇒ Object (readonly)
Maximum number of bytes that can be written
      21 22 23  | 
    
      # File 'lib/rubygems/package/tar_writer.rb', line 21 def limit @limit end  | 
  
#written ⇒ Object (readonly)
Number of bytes written
      26 27 28  | 
    
      # File 'lib/rubygems/package/tar_writer.rb', line 26 def written @written end  | 
  
Instance Method Details
#write(data) ⇒ Object
Writes data onto the IO, raising a FileOverflow exception if the number of bytes will be more than #limit
      41 42 43 44 45 46 47 48  | 
    
      # File 'lib/rubygems/package/tar_writer.rb', line 41 def write(data) if data.bytesize + @written > @limit raise FileOverflow, "You tried to feed more data than fits in the file." end @io.write data @written += data.bytesize data.bytesize end  |