Class: MiniTarball::LimitedSizeStream
- Inherits:
-
Object
- Object
- MiniTarball::LimitedSizeStream
- Defined in:
- lib/mini_tarball/streams/limited_size_stream.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#end_position ⇒ Object
readonly
Returns the value of attribute end_position.
-
#start_position ⇒ Object
readonly
Returns the value of attribute start_position.
Instance Method Summary collapse
-
#initialize(io, start_position:, max_file_size:) ⇒ LimitedSizeStream
constructor
A new instance of LimitedSizeStream.
- #write(data) ⇒ Object
Constructor Details
#initialize(io, start_position:, max_file_size:) ⇒ LimitedSizeStream
Returns a new instance of LimitedSizeStream.
12 13 14 15 16 |
# File 'lib/mini_tarball/streams/limited_size_stream.rb', line 12 def initialize(io, start_position:, max_file_size:) @io = io @start_position = start_position @end_position = start_position + max_file_size end |
Instance Attribute Details
#end_position ⇒ Object (readonly)
Returns the value of attribute end_position.
8 9 10 |
# File 'lib/mini_tarball/streams/limited_size_stream.rb', line 8 def end_position @end_position end |
#start_position ⇒ Object (readonly)
Returns the value of attribute start_position.
8 9 10 |
# File 'lib/mini_tarball/streams/limited_size_stream.rb', line 8 def start_position @start_position end |
Instance Method Details
#write(data) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/mini_tarball/streams/limited_size_stream.rb', line 18 def write(data) current_position = io.pos if current_position < start_position || current_position + data.bytesize > end_position raise WriteOutOfRangeError.new("Writing outside of limits not allowed") end io.write(data) end |