dshelf 0.2.5 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dshelf/dfile.rb +41 -5
- data/lib/dshelf/dir.rb +2 -0
- data/lib/dshelf/file.rb +6 -0
- data/lib/dshelf.rb +1 -1
- metadata +3 -3
data/lib/dshelf/dfile.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rest_client'
|
2
|
+
# require 'httpclient'
|
2
3
|
require 'mime/types'
|
3
4
|
|
4
5
|
class DistributedFile
|
@@ -71,6 +72,15 @@ class DistributedFile
|
|
71
72
|
end
|
72
73
|
|
73
74
|
def read length=0, offset=0
|
75
|
+
# if RUBY_VERSION >= '1.8.7' then
|
76
|
+
# # stream
|
77
|
+
# Stream.new "#{server_url}/storage#{URI.escape absolutepath}"
|
78
|
+
# else
|
79
|
+
# read_full length, offset
|
80
|
+
# end
|
81
|
+
# end
|
82
|
+
#
|
83
|
+
# def read_full length=0, offset=0
|
74
84
|
params = {}
|
75
85
|
params[:length] = length unless length == 0
|
76
86
|
params[:offset] = offset unless offset == 0
|
@@ -79,17 +89,29 @@ class DistributedFile
|
|
79
89
|
case response.code
|
80
90
|
when 200
|
81
91
|
response
|
92
|
+
when 402
|
93
|
+
raise Errno::ENOSPC
|
82
94
|
when 404
|
83
95
|
raise Errno::ENOENT
|
84
|
-
end
|
96
|
+
end
|
85
97
|
end
|
86
98
|
end
|
87
99
|
|
100
|
+
def puts *args
|
101
|
+
write args.join("\n")
|
102
|
+
end
|
103
|
+
|
88
104
|
def write string
|
89
|
-
RestClient.put "#{server_url}/storage#{URI.escape absolutepath}", string, :content_type => mimetype
|
90
|
-
|
105
|
+
RestClient.put "#{server_url}/storage#{URI.escape absolutepath}", string, :content_type => mimetype do |response, request, result|
|
106
|
+
case response.code
|
107
|
+
when 204
|
108
|
+
string.size
|
109
|
+
when 402
|
110
|
+
raise Errno::ENOSPC
|
111
|
+
end
|
112
|
+
end
|
91
113
|
end
|
92
|
-
|
114
|
+
|
93
115
|
# File.open(filename, mode="r" [, opt]) => file
|
94
116
|
# File.open(filename [, mode [, perm]] [, opt]) => file
|
95
117
|
# File.open(filename, mode="r" [, opt]) {|file| block } => obj
|
@@ -104,8 +126,22 @@ class DistributedFile
|
|
104
126
|
f
|
105
127
|
end
|
106
128
|
end
|
107
|
-
|
129
|
+
|
108
130
|
def method_missing method
|
109
131
|
raise "Distributed File error: #{method} not implemented"
|
110
132
|
end
|
111
133
|
end
|
134
|
+
|
135
|
+
# class Stream
|
136
|
+
# def initialize path
|
137
|
+
# @path = path
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# def each
|
141
|
+
# HTTPClient.get_content(@path) do |chunk|
|
142
|
+
# p "chunk rcv: #{chunk.size}"
|
143
|
+
# yield chunk
|
144
|
+
# p "chunk rcv rt: #{chunk.size}"
|
145
|
+
# end
|
146
|
+
# end
|
147
|
+
# end
|
data/lib/dshelf/dir.rb
CHANGED
data/lib/dshelf/file.rb
CHANGED
@@ -33,6 +33,8 @@ class File
|
|
33
33
|
case response.code
|
34
34
|
when 200
|
35
35
|
args.size
|
36
|
+
when 402
|
37
|
+
raise Errno::ENOSPC
|
36
38
|
when 404
|
37
39
|
raise Errno::ENOENT
|
38
40
|
end
|
@@ -47,6 +49,8 @@ class File
|
|
47
49
|
case response.code
|
48
50
|
when 200
|
49
51
|
0
|
52
|
+
when 402
|
53
|
+
raise Errno::ENOSPC
|
50
54
|
when 404
|
51
55
|
raise Errno::ENOENT
|
52
56
|
end
|
@@ -60,6 +64,8 @@ class File
|
|
60
64
|
case response.code
|
61
65
|
when 200
|
62
66
|
0
|
67
|
+
when 402
|
68
|
+
raise Errno::ENOSPC
|
63
69
|
when 404
|
64
70
|
raise Errno::ENOENT
|
65
71
|
end
|
data/lib/dshelf.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 7
|
9
|
+
version: 0.2.7
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Phil Pirozhkov
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-11-08 00:00:00 +03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|