Class: Archive::Tar::Minitar::Writer::BoundedStream

Inherits:
RestrictedStream show all
Defined in:
lib/shoes/minitar.rb

Overview

A RestrictedStream that also has a size limit.

Defined Under Namespace

Classes: FileOverflow

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (BoundedStream) initialize(io, limit)

Returns a new instance of BoundedStream



272
273
274
275
276
# File 'lib/shoes/minitar.rb', line 272

def initialize(io, limit)
  @io       = io
  @limit    = limit
  @written  = 0
end

Instance Attribute Details

- (Object) limit (readonly)

The maximum number of bytes that may be written to this data stream.



268
269
270
# File 'lib/shoes/minitar.rb', line 268

def limit
  @limit
end

- (Object) written (readonly)

The current total number of bytes written to this data stream.



270
271
272
# File 'lib/shoes/minitar.rb', line 270

def written
  @written
end

Instance Method Details

- (Object) write(data)

Raises:



278
279
280
281
282
283
# File 'lib/shoes/minitar.rb', line 278

def write(data)
  raise FileOverflow if (data.size + @written) > @limit
  @io.write(data)
  @written += data.size
  data.size
end