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

Inherits:
RestrictedStream show all
Defined in:
lib/amp/dependencies/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

#initialize(io, limit) ⇒ BoundedStream

Returns a new instance of BoundedStream.



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

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

Instance Attribute Details

#limitObject (readonly)

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



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

def limit
  @limit
end

#writtenObject (readonly)

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



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

def written
  @written
end

Instance Method Details

#write(data) ⇒ Object

Raises:



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

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