Harbor::BlockIO
Used by Harbor::Response#send_file and Harbor::Response#stream_file to send large files or streams in chunks. This is a fallback measure for the cases where X-Sendfile cannot be used.
Parent
Methods
Public Class Methods
block_size()
# File lib/harbor/block_io.rb, line 9 9: def self.block_size 10: @@block_size ||= 500_000 # 500kb 11: end
block_size=(value)
# File lib/harbor/block_io.rb, line 13 13: def self.block_size=(value) 14: raise ArgumentError.new("Harbor::BlockIO::block_size value must be a Fixnum") unless value.is_a?(Fixnum) 15: @@block_size = value 16: end
new(path_or_io)
# File lib/harbor/block_io.rb, line 18 18: def initialize(path_or_io) 19: case path_or_io 20: when ::IO 21: @io = path_or_io 22: @size = @io.stat.size 23: when StringIO 24: @io = path_or_io 25: @size = @io.size 26: when Harbor::FileStore::File 27: @io = path_or_io 28: @size = @io.size 29: @path = path_or_io.absolute_path 30: when Pathname 31: @path = path_or_io.expand_path.to_s 32: @io = path_or_io.open('r') 33: @size = path_or_io.size 34: else 35: @path = path_or_io.to_s 36: @io = ::File::open(@path, 'r') 37: @size = ::File.size(@path) 38: end 39: end