libgfapi-ruby 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a3c0d38b5bcdd80b4513bb96b4342ff4972703b
4
- data.tar.gz: 95d79a7abffbaba6e5d2f9c57598d41fac3ab6ee
3
+ metadata.gz: 0669cfea34e893de481678cc8e1b9a67e795cbf4
4
+ data.tar.gz: 1b71461efff897518ebcfa0dc06c7e3c2f9c3e29
5
5
  SHA512:
6
- metadata.gz: afded3940c97df13542b43559e7e515b28847271d52f972387fc25caad4f5de0f7dd7e2fc8ed62eed3c2182539ebccdde533c0a51ef42dd565b347a9f7996673
7
- data.tar.gz: d8ac6eea130f373fa3d4003fcf2b12a223b872f99208da25f20c8d04386a008ff2e952e32892ca501b17658880bc7f6af612ffd9c4d5eb83bb4bd7ecb6961d31
6
+ metadata.gz: ba03a9428231f95351eb74732df8c33240453bc59a3a051aadae9f5d9c074ce5ecb698fcc7bc55a280de11498aaa810b959fb72e9e322d139d1ede07057f4921
7
+ data.tar.gz: 04db7ce3f2046076f6af679d02eea68f17a0da9ac086031321fe6c0aa97dc81f72f0524fb0f1952ebec100d7f6da6cecf12a34a9b6e151584de700b6d100d323
data/README.md CHANGED
@@ -31,10 +31,13 @@ GlusterFS.init fs
31
31
  GlusterFS.mkdir fs, '/some_dir', 0755
32
32
 
33
33
  # Write a file
34
- fd = GlusterFS.creat fs, '/somedir/my_file', 2, 0755
35
- str = "test data\n"
36
- GlusterFS.write fd, str, str.size + 1, 0
37
- GlusterFS.close fd
34
+ file = File.open('/some/file')
35
+ size = GlusterFS::File.write(fs, '/gfs/file/path', file)
36
+ puts "Written #{size} bytes"
37
+
38
+ # Read a file
39
+ file = GlusterFS::File.read(fs, '/gfs/file/path')
40
+ contents = file.read
38
41
 
39
42
  # Destroy virtual mount
40
43
  GlusterFS.fini fs
data/lib/glusterfs.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "glusterfs/version"
2
+ require "glusterfs/file"
2
3
  require "ffi"
3
4
 
4
5
  module GlusterFS
@@ -310,8 +311,8 @@ module GlusterFS
310
311
  int glfs_write_async (glfs_fd_t *fd, const void *buf, size_t count, int flags,
311
312
  glfs_io_cbk fn, void *data) __THROW;
312
313
  =end
313
- attach_function :read, :glfs_read, [:pointer, :string, :uint, :int], :uint
314
- attach_function :write, :glfs_write, [:pointer, :string, :uint, :int], :uint
314
+ attach_function :read, :glfs_read, [:pointer, :pointer, :uint, :int], :uint
315
+ attach_function :write, :glfs_write, [:pointer, :pointer, :uint, :int], :uint
315
316
  # TODO async
316
317
 
317
318
  =begin
@@ -0,0 +1,25 @@
1
+ require "tempfile"
2
+ class GlusterFS::File
3
+ class << self
4
+ def read(fs, path, buf_size = 4092)
5
+ fd = GlusterFS.open(fs, path, 0)
6
+ temp = Tempfile.new(path.gsub('/', '-'))
7
+ buff = FFI::MemoryPointer.new(:char, buf_size)
8
+ res = 1
9
+ while res > 0
10
+ res = GlusterFS.read(fd, buff, buf_size, 0)
11
+ temp.write(buff.get_bytes(0, res)) if res > 0
12
+ end
13
+ GlusterFS.close(fd)
14
+ temp.rewind
15
+ temp
16
+ end
17
+
18
+ def write(fs, path, file, perms = 0644)
19
+ fd = GlusterFS.creat(fs, path, 2, perms)
20
+ res = GlusterFS.write(fd, file.read, file.size, 0)
21
+ GlusterFS.close(fd)
22
+ res
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module GlusterFS
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libgfapi-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Varaneckas
@@ -65,6 +65,7 @@ files:
65
65
  - README.md
66
66
  - Rakefile
67
67
  - lib/glusterfs.rb
68
+ - lib/glusterfs/file.rb
68
69
  - lib/glusterfs/version.rb
69
70
  - libgfapi-ruby.gemspec
70
71
  homepage: https://github.com/spajus/libgfapi-ruby