Harbor::FileStore::File
Parent
Attributes
Public Class Methods
Public Instance Methods
absolute_path()
Returns the full path to this file
# File lib/harbor/file_store/file.rb, line 95 95: def absolute_path 96: (@store.root + @path).to_s 97: end
close()
# File lib/harbor/file_store/file.rb, line 87 87: def close 88: @stream.close if @stream 89: @stream = nil 90: end
copy_on_read()
# File lib/harbor/file_store/file.rb, line 27 27: def copy_on_read 28: return @copy_on_read if @copy_on_read 29: 30: @copy_on_read = [] 31: if store.options[:copy_on_read] 32: store.options[:copy_on_read].each do |name| 33: @copy_on_read << Harbor::FileStore[name].get(@path) 34: end 35: end 36: 37: @copy_on_read 38: end
copy_on_write()
# File lib/harbor/file_store/file.rb, line 14 14: def copy_on_write 15: return @copy_on_write if @copy_on_write 16: 17: @copy_on_write = [] 18: if store.options[:copy_on_write] 19: store.options[:copy_on_write].each do |name| 20: @copy_on_write << Harbor::FileStore[name].get(@path) 21: end 22: end 23: 24: @copy_on_write 25: end
exists?()
# File lib/harbor/file_store/file.rb, line 99 99: def exists? 100: store.exists?(path) 101: end
open(mode = "r")
# File lib/harbor/file_store/file.rb, line 83 83: def open(mode = "r") 84: @stream ||= store.open(path, mode) 85: end
read(bytes = nil)
# File lib/harbor/file_store/file.rb, line 64 64: def read(bytes = nil) 65: open("r") 66: 67: data = @stream.read(bytes) 68: 69: copy_on_read.each { |file| file.write(data) } 70: 71: unless bytes && data 72: @stream.close 73: @stream = nil 74: end 75: 76: data 77: end
write(data)
# File lib/harbor/file_store/file.rb, line 40 40: def write(data) 41: open("wb") 42: 43: copy_on_write.each do |file| 44: if store.options[:async_copy] 45: @pending_writes << lambda { file.write(data) } 46: else 47: file.write(data) 48: end 49: end 50: 51: if data 52: @stream.write(data) 53: else 54: @stream.close 55: @stream = nil 56: 57: Thread.new { 58: @pending_writes.each { |write| write.call } 59: @pending_writes = [] 60: } if store.options[:async_copy] 61: end 62: end