midori-contrib 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/midori-contrib.rb +10 -4
- data/lib/midori-contrib/file.rb +44 -42
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ec714a6aa1722648a8a599034891aed049db61d
|
4
|
+
data.tar.gz: 766542c9806b43408d522aac82d062db79a6536c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b38aee10d497ecac9a8131eff3823ab0a3ffb6ca28853b11fac98fb239b50c483d9a52aa254c48964c3446283421eccfcb7ca891ac961b4e5296e8a1135de68
|
7
|
+
data.tar.gz: ca270cc232ad97a1cdd1352e8430c80e3e2a8ed552c941005b3623eba53e3749dfec27a3aba4eb483beacc0755f2441a52b96e27392eae0f486a915997d7b054
|
data/lib/midori-contrib.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
# Midori
|
2
|
-
module
|
3
|
-
#
|
4
|
-
|
1
|
+
# Midori Module
|
2
|
+
module Midori
|
3
|
+
# Midori Contrib Module
|
4
|
+
module Contrib
|
5
|
+
# Current Version Code
|
6
|
+
VERSION = '0.1.0'.freeze
|
7
|
+
end
|
5
8
|
end
|
9
|
+
|
10
|
+
# For API backward compatibility
|
11
|
+
MidoriContrib = Midori::Contrib
|
data/lib/midori-contrib/file.rb
CHANGED
@@ -1,53 +1,55 @@
|
|
1
1
|
##
|
2
2
|
# Midori Extension of File reading and writing
|
3
|
-
module
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module Midori
|
4
|
+
module Contrib
|
5
|
+
class File
|
6
|
+
# Init File object
|
7
|
+
# @param [Array] args same args like File.new
|
8
|
+
def initialize(*args)
|
9
|
+
@file = ::File.new(*args)
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
# read file
|
13
|
+
# @return [String] string readed
|
14
|
+
def read
|
15
|
+
await(Promise.new do |resolve|
|
16
|
+
data = ''
|
17
|
+
EventLoop.register(@file, :r) do
|
18
|
+
if @file.eof?
|
19
|
+
EventLoop.deregister(@file)
|
20
|
+
resolve.call(data)
|
21
|
+
else
|
22
|
+
data << @file.read_nonblock(16384)
|
23
|
+
end
|
22
24
|
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
25
|
+
end)
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
# write file
|
29
|
+
# @param [String] data string to be written
|
30
|
+
def write(data)
|
31
|
+
await(Promise.new do |resolve|
|
32
|
+
written = 0
|
33
|
+
EventLoop.register(@file, :w) do
|
34
|
+
written += @file.write_nonblock(data[written..-1])
|
35
|
+
if written == data.size
|
36
|
+
EventLoop.deregister(@file)
|
37
|
+
resolve.call(written)
|
38
|
+
end
|
37
39
|
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
40
|
+
end)
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
# raw file object
|
44
|
+
# @return [File] file
|
45
|
+
def raw
|
46
|
+
@file
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
# Close the file
|
50
|
+
def close
|
51
|
+
@file.close
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midori-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- HeckPsi Lab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06
|
11
|
+
date: 2017-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-midori
|