drb_fileclient-reader 0.1.8 → 0.1.9
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: 85b8ff669621464afe7d8f289fa268fe0a368044bead6dab1e1ecb9337748e5c
|
4
|
+
data.tar.gz: 6499258427fcc20fc1049d7cc063a37ed17f5b0baed61d51758b06750de16407
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3af5c2980d39a6fe3e14ad0e2207766fd9776a34c0c354ae139babd6643e6eae5f3ea4fb42f4d2389d16c68bdb6fa0ad0c6991d25ea03eb51a96a3626ab60b66
|
7
|
+
data.tar.gz: 39b599fc6d09d1730713772af6613f306f79be64d4d1f2ae8ff5449c3cd600ec0f862ee66c854c59b6ea76770be92ba6f3014a114b1b23a8aae528b7d704fdc5
|
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'
|
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
|