Harbor Documentation

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.

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

Public Instance Methods

close()

      # File lib/harbor/block_io.rb, line 53
53:     def close
54:       @io.close
55:     end

each()

      # File lib/harbor/block_io.rb, line 57
57:     def each
58:       while data = @io.read(Harbor::BlockIO::block_size) do
59:         yield data
60:       end
61:     end

path()

      # File lib/harbor/block_io.rb, line 41
41:     def path
42:       @path
43:     end

size()

      # File lib/harbor/block_io.rb, line 49
49:     def size
50:       @size
51:     end

to_s()

      # File lib/harbor/block_io.rb, line 45
45:     def to_s
46:       @io.read
47:     end