drb_fileclient-reader 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/drb_fileclient-reader.rb +78 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35e7b5fb46fc689b46d8fd08096bee947c0f15530d70c66b1f0e90777b061b41
|
4
|
+
data.tar.gz: cdf706aa2b13c2071d9c03ec7532df068d6a5ba06b0ffd1fd3b16e4ea050ec30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d9d7f66b117d210ab42bfb2221c1422b4235f5b68952640754eff19bbea197b76d978d06a689ac567675bbb4e0e14c434a78f8b89b06bcb7f558d0661626403
|
7
|
+
data.tar.gz: aa9bdd3b7ef96ba9c1b035c34f7cd5744848075ab0ca873cd108b0baf0b1e0c7d7965c46a1e6b4cf6fa2e0951cf76b2e8b66d17775b9a1189bf2f4e4aea23413
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -2,8 +2,85 @@
|
|
2
2
|
|
3
3
|
# file: drb_fileclient-reader.rb
|
4
4
|
|
5
|
+
require 'drb/drb'
|
6
|
+
require 'c32'
|
5
7
|
|
6
|
-
# testing, please ignore this version
|
7
8
|
|
8
9
|
class DRbFileClientReader
|
10
|
+
using ColouredText
|
11
|
+
|
12
|
+
def initialize(location=nil, host: nil, port: '61010', debug: false)
|
13
|
+
|
14
|
+
@debug = debug
|
15
|
+
@@file ||= nil
|
16
|
+
|
17
|
+
if location then
|
18
|
+
|
19
|
+
host = location[/(?<=^dfs:\/\/)[^\/:]+/]
|
20
|
+
port = location[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1] || '61010'
|
21
|
+
@@directory ||= location[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1]
|
22
|
+
else
|
23
|
+
@@directory ||= nil
|
24
|
+
end
|
25
|
+
|
26
|
+
DRb.start_service
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def exist?(filename=@@filename)
|
31
|
+
|
32
|
+
return File.exist? filename unless @@directory or filename =~ /^dfs:\/\//
|
33
|
+
|
34
|
+
if filename =~ /^dfs:\/\// then
|
35
|
+
|
36
|
+
file, filename2 = parse_path(filename)
|
37
|
+
@@file ||= file
|
38
|
+
|
39
|
+
else
|
40
|
+
|
41
|
+
filename2 = File.join(@@directory, filename)
|
42
|
+
end
|
43
|
+
|
44
|
+
@@file.exist?(filename2)
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def read(filename=@@filename)
|
49
|
+
|
50
|
+
return File.read(filename) unless @@directory or filename =~ /^dfs:\/\//
|
51
|
+
|
52
|
+
if filename =~ /^dfs:\/\// then
|
53
|
+
file, path = parse_path(filename)
|
54
|
+
@@file ||= file
|
55
|
+
else
|
56
|
+
path = File.join(@@directory, filename)
|
57
|
+
end
|
58
|
+
|
59
|
+
@@file.read path
|
60
|
+
end
|
61
|
+
|
62
|
+
protected
|
63
|
+
|
64
|
+
def parse_path(filename)
|
65
|
+
|
66
|
+
host = filename[/(?<=^dfs:\/\/)[^\/:]+/]
|
67
|
+
@host = host if host
|
68
|
+
|
69
|
+
port = filename[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1] || '61010'
|
70
|
+
|
71
|
+
file_server = DRbObject.new nil, "druby://#{host || @host}:#{port}"
|
72
|
+
[file_server, filename[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1], ("dfs://%s:%s" % [host, port])]
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
class DfsFile
|
79
|
+
|
80
|
+
@client = DRbFileClientReader.new
|
81
|
+
|
82
|
+
def self.exist?(filename) @client.exist?(filename) end
|
83
|
+
def self.exists?(filename) @client.exist?(filename) end
|
84
|
+
def self.read(filename) @client.read(filename) end
|
85
|
+
|
9
86
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|