cpee-dstore 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/cpee-dstore.gemspec +1 -1
- data/lib/cpee-dstore/implementation.rb +39 -7
- data/lib/cpee-dstore/implementation.xml +14 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ccd12e54e8d15208553763a9bc03e339892a4bfca6b5d777cc18e8218bba196
|
|
4
|
+
data.tar.gz: af2d5eba2eeb9b3e148ce4d06df8555d4101a57d5cbb572b24c48e15be100722
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2defba9a5d8c816a6d46d73e9db7e0bb555b223c22e79ddfd3a37803329552c35893e1456c2a6b87b6ae9d58a94df24e07a9713f325c00ebaccb4acb86c10631
|
|
7
|
+
data.tar.gz: '08253bf3a7fe587488606550fcacc968d6cee8a0605a064c7f365656de7ca686461cdbbd10970c7d6d5b8f013cf043b16829028ce1bc6d7df778d7c583f14383'
|
data/cpee-dstore.gemspec
CHANGED
|
@@ -20,6 +20,27 @@ require 'mimemagic'
|
|
|
20
20
|
require 'riddl/server'
|
|
21
21
|
require 'fileutils'
|
|
22
22
|
|
|
23
|
+
class File
|
|
24
|
+
def tail(n)
|
|
25
|
+
buffer = 1024
|
|
26
|
+
idx = [size - buffer, 0].max
|
|
27
|
+
chunks = []
|
|
28
|
+
lines = 0
|
|
29
|
+
|
|
30
|
+
begin
|
|
31
|
+
seek(idx)
|
|
32
|
+
chunk = read(buffer)
|
|
33
|
+
lines += chunk.count("\n")
|
|
34
|
+
chunks.unshift chunk
|
|
35
|
+
idx -= buffer
|
|
36
|
+
end while lines < ( n + 1 ) && pos != 0
|
|
37
|
+
|
|
38
|
+
tail_of_file = chunks.join('')
|
|
39
|
+
ary = tail_of_file.split("\n")
|
|
40
|
+
ary[ ary.size - n, ary.size - 1 ].join("\n")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
23
44
|
module CPEE
|
|
24
45
|
module DStore
|
|
25
46
|
SERVER = File.expand_path(File.join(__dir__,'implementation.xml'))
|
|
@@ -29,7 +50,12 @@ module CPEE
|
|
|
29
50
|
file = File.join(@a[0],@r[-2],@r[-1])
|
|
30
51
|
meta = file + '.mimetype'
|
|
31
52
|
if File.exist?(file) && File.exist?(meta)
|
|
32
|
-
|
|
53
|
+
f = File.open(file,'rb')
|
|
54
|
+
if @p.length > 0 && @p[0].name == 'tail'
|
|
55
|
+
Riddl::Parameter::Complex.new('file',File.read(meta).strip,f.tail(@p[0].value.to_i))
|
|
56
|
+
else
|
|
57
|
+
Riddl::Parameter::Complex.new('file',File.read(meta).strip,f)
|
|
58
|
+
end
|
|
33
59
|
else
|
|
34
60
|
@status = 404
|
|
35
61
|
nil
|
|
@@ -39,11 +65,17 @@ module CPEE
|
|
|
39
65
|
|
|
40
66
|
class DoPut < Riddl::Implementation #{{{
|
|
41
67
|
def response
|
|
68
|
+
if @p[0].name == 'append'
|
|
69
|
+
mode = 'ab'
|
|
70
|
+
@p.shift
|
|
71
|
+
else
|
|
72
|
+
mode = 'wb'
|
|
73
|
+
end
|
|
42
74
|
name = @r[-1]
|
|
43
75
|
dir = File.join(@a[0],@r[-2])
|
|
44
76
|
FileUtils.mkdir_p(dir)
|
|
45
77
|
|
|
46
|
-
File.open(File.join(dir,name),
|
|
78
|
+
File.open(File.join(dir,name),mode) do |f|
|
|
47
79
|
IO.copy_stream(@p[0].value,f)
|
|
48
80
|
mime = MimeMagic.by_magic(@p[0].value.read)
|
|
49
81
|
mt = if mime.nil?
|
|
@@ -62,11 +94,11 @@ module CPEE
|
|
|
62
94
|
opts[:data_dir] ||= File.expand_path(File.join(__dir__,'data'))
|
|
63
95
|
|
|
64
96
|
Proc.new do
|
|
65
|
-
on resource do
|
|
66
|
-
on resource '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' do
|
|
67
|
-
on resource '[a-z_][a-zA-Z0-9_]*' do
|
|
68
|
-
run DoGet, opts[:data_dir] if get
|
|
69
|
-
run DoPut, opts[:data_dir] if put '
|
|
97
|
+
on resource do
|
|
98
|
+
on resource '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' do
|
|
99
|
+
on resource '[a-z_][a-zA-Z0-9_]*' do
|
|
100
|
+
run DoGet, opts[:data_dir] if get 'rfile'
|
|
101
|
+
run DoPut, opts[:data_dir] if put 'ifile'
|
|
70
102
|
end
|
|
71
103
|
end
|
|
72
104
|
end
|
|
@@ -17,15 +17,26 @@
|
|
|
17
17
|
-->
|
|
18
18
|
|
|
19
19
|
<description xmlns="http://riddl.org/ns/description/1.0" xmlns:ann="http://riddl.org/ns/annotation/1.0" xmlns:xi="http://www.w3.org/2001/XInclude" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
|
|
20
|
-
<message name="
|
|
20
|
+
<message name="ifile">
|
|
21
|
+
<optional>
|
|
22
|
+
<parameter name="append" type="string"/>
|
|
23
|
+
</optional>
|
|
24
|
+
<parameter name="file" mimetype="*"/>
|
|
25
|
+
</message>
|
|
26
|
+
<message name="rfile">
|
|
27
|
+
<optional>
|
|
28
|
+
<parameter name="tail" type="integer"/>
|
|
29
|
+
</optional>
|
|
30
|
+
</message>
|
|
31
|
+
<message name="ofile">
|
|
21
32
|
<parameter name="file" mimetype="*"/>
|
|
22
33
|
</message>
|
|
23
34
|
|
|
24
35
|
<resource>
|
|
25
36
|
<resource relative="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}">
|
|
26
37
|
<resource relative='[a-z_][a-zA-Z0-9_]*'>
|
|
27
|
-
<get out="
|
|
28
|
-
<put in="
|
|
38
|
+
<get in="rfile" out="ofile"/>
|
|
39
|
+
<put in="ifile"/>
|
|
29
40
|
</resource>
|
|
30
41
|
</resource>
|
|
31
42
|
</resource>
|