ganapati 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ganapati/client.rb +14 -7
  2. metadata +3 -3
@@ -34,17 +34,24 @@ module Ganapati
34
34
  # copy remote file to local
35
35
  def get(remotepath, destpath)
36
36
  Kernel.open(destpath, 'w') { |dest|
37
- open(remotepath) { |source|
38
- size = source.length
39
- index = 0
40
- while index < size
41
- dest.write(source.read(index, 1048576))
42
- index += 1048576
43
- end
37
+ readchunks(remotepath) { |chunk|
38
+ dest.write chunk
44
39
  }
45
40
  }
46
41
  end
47
42
 
43
+ # yeild chunksize of path one chunk at a time
44
+ def readchunks(path, chunksize=1048576)
45
+ open(path) { |source|
46
+ size = source.length
47
+ index = 0
48
+ while index < size
49
+ yield source.read(index, chunksize)
50
+ index += chunksize
51
+ end
52
+ }
53
+ end
54
+
48
55
  # for writing to a new file
49
56
  def create(path, &block)
50
57
  file_handle :create, path, &block
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ganapati
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Muller