Class: GlusterFS::File
- Inherits:
-
Object
- Object
- GlusterFS::File
- Defined in:
- lib/glusterfs/file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Instance Method Summary collapse
- #delete ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(volume, path) ⇒ File
constructor
A new instance of File.
- #lstat ⇒ Object
- #read(buf_size = 4092) ⇒ Object
- #read_file(buf_size = 4092) ⇒ Object
- #size ⇒ Object
- #write(data, perms = 0644) ⇒ Object
- #write_file(file, perms = 0644, buffer_size = 4092) ⇒ Object
Constructor Details
#initialize(volume, path) ⇒ File
Returns a new instance of File.
4 5 6 7 |
# File 'lib/glusterfs/file.rb', line 4 def initialize(volume, path) @volume = volume @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/glusterfs/file.rb', line 3 def path @path end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
3 4 5 |
# File 'lib/glusterfs/file.rb', line 3 def volume @volume end |
Instance Method Details
#delete ⇒ Object
58 59 60 |
# File 'lib/glusterfs/file.rb', line 58 def delete GlusterFS.unlink(@volume.fs, @path) end |
#exists? ⇒ Boolean
68 69 70 |
# File 'lib/glusterfs/file.rb', line 68 def exists? GlusterFS::Stat.file?(lstat) end |
#lstat ⇒ Object
62 63 64 65 66 |
# File 'lib/glusterfs/file.rb', line 62 def lstat data = GlusterFS::Stat.new GlusterFS.lstat(@volume.fs, @path, data) data end |
#read(buf_size = 4092) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/glusterfs/file.rb', line 25 def read(buf_size = 4092) check_exists fd = GlusterFS.open(@volume.fs, @path, 0) temp = '' buff = FFI::MemoryPointer.new(:char, buf_size) res = 1 lstat while res > 0 res = GlusterFS.read(fd, buff, buf_size, 0) temp << buff.get_bytes(0, res) if res > 0 end GlusterFS.close(fd) temp end |
#read_file(buf_size = 4092) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/glusterfs/file.rb', line 9 def read_file(buf_size = 4092) check_exists fd = GlusterFS.open(@volume.fs, @path, 0) temp = Tempfile.new(path.gsub('/', '-')) temp.binmode buff = FFI::MemoryPointer.new(:char, buf_size) res = 1 while res > 0 res = GlusterFS.read(fd, buff, buf_size, 0) temp.write(buff.get_bytes(0, res)) if res > 0 end GlusterFS.close(fd) temp.rewind temp end |
#size ⇒ Object
72 73 74 |
# File 'lib/glusterfs/file.rb', line 72 def size lstat[:st_size] end |
#write(data, perms = 0644) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/glusterfs/file.rb', line 51 def write(data, perms = 0644) fd = GlusterFS.creat(@volume.fs, path, 2, perms) res = GlusterFS.write(fd, data, data.size, 0) GlusterFS.close(fd) res end |
#write_file(file, perms = 0644, buffer_size = 4092) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/glusterfs/file.rb', line 40 def write_file(file, perms = 0644, buffer_size = 4092) fd = GlusterFS.creat(@volume.fs, path, 2, perms) res = 0 until file.eof? chunk = file.read(buffer_size) res += GlusterFS.write(fd, chunk, chunk.size , 0) end GlusterFS.close(fd) res end |