flyingv 0.1.1 → 0.2.0
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.
- data/VERSION +1 -1
- data/flyingv.gemspec +2 -2
- data/lib/flyingv.rb +51 -1
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/flyingv.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{flyingv}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tomasz Stachewicz"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-04}
|
13
13
|
s.description = %q{Ruby wrapper for interacting with OpenKeyValue key-value storage}
|
14
14
|
s.email = %q{tomekrs@o2.pl}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/flyingv.rb
CHANGED
@@ -13,5 +13,55 @@ class FlyingV
|
|
13
13
|
value = value.to_json if(value.is_a?(Hash) or value.is_a?(Array))
|
14
14
|
Net::HTTP.post_form(URI.parse("http://api.openkeyval.org/#{key}"), {'data' => value})
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
|
+
def self.post_file(key, path)
|
18
|
+
size = File.size(path)
|
19
|
+
content = File.open(path).read
|
20
|
+
original_name = File.basename(path)
|
21
|
+
self.post(key, {"content" => content, "original_name" => original_name})
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.put_file(key, path)
|
25
|
+
size = File.size(path)
|
26
|
+
chunks = (size / 2048.0).ceil
|
27
|
+
return self.post_file(key, path) if(chunks == 1)
|
28
|
+
original_name = File.basename(path)
|
29
|
+
content = File.open(path).read
|
30
|
+
next_chunk_key = nil
|
31
|
+
chunk_keys = []
|
32
|
+
sanity_check = ""
|
33
|
+
chunks.downto(1) do |i|
|
34
|
+
k = "#{key}_chunk_#{i}"
|
35
|
+
chunk_keys << k
|
36
|
+
if(i == chunks)
|
37
|
+
chunk_content = content[((i-1)*2048)..-1]
|
38
|
+
else
|
39
|
+
chunk_content = content[((i-1)*2048)..(i*2048-1)]
|
40
|
+
end
|
41
|
+
sanity_check += chunk_content
|
42
|
+
puts "storing key: #{k}, content size #{chunk_content.size}"
|
43
|
+
self.post(k, {
|
44
|
+
"content" => chunk_content,
|
45
|
+
"master_key" => key,
|
46
|
+
"chunk" => i,
|
47
|
+
"next" => next_chunk_key})
|
48
|
+
next_chunk_key = k
|
49
|
+
end
|
50
|
+
puts "sanity check size = #{sanity_check.size}, content size = #{content.size}"
|
51
|
+
self.post(key, {
|
52
|
+
"original_name" => original_name,
|
53
|
+
"chunk_keys" => chunk_keys.reverse})
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.get_file(key, target_path)
|
57
|
+
master = self.get(key)
|
58
|
+
f = File.open(target_path, "w")
|
59
|
+
master["chunk_keys"].each do |chunk_key|
|
60
|
+
chunk = self.get(chunk_key)
|
61
|
+
puts "master key sanity check PASSED! -- getting #{chunk_key}" if(chunk["master_key"] == key)
|
62
|
+
f.write(chunk["content"])
|
63
|
+
end
|
64
|
+
f.close
|
65
|
+
puts "complete"
|
66
|
+
end
|
17
67
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flyingv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tomasz Stachewicz
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-04 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|