em-zipper 0.0.2 → 0.0.3
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/Gemfile +6 -0
- data/Gemfile.lock +14 -1
- data/benchmarkz/em-zipper.rb +111 -0
- data/examples/file.rb +1 -1
- data/examples/files/sample1.txt +0 -94981
- data/examples/io.rb +1 -1
- data/lib/em-zipper/base.rb +30 -28
- data/lib/em-zipper/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64af8eac1c0ad6532476956a5b9852c8cc6d8acf
|
4
|
+
data.tar.gz: 16ef90ab41a5ee6416f5ac4b0979aa4b6ef71f21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ece25c89c5c737918b9bc3a43c0aada19034166523091441d3c52e1c5ebde846ba35d9e21ffeefe1f3ad0b18c07cb85f80a1d95301cf9ff7946f415851ce36e2
|
7
|
+
data.tar.gz: 08fa21a4d870487480b779d616fdcd0cf265e27d27aaa526d0fc827466144110a169d7871558c6d8b0141deaf0b35f13e88b9060d7dd0ac4504eb55392daafa2
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
em-zipper (0.0.
|
4
|
+
em-zipper (0.0.2)
|
5
5
|
em-http-request (>= 1.1.1)
|
6
6
|
eventmachine (>= 1.0.3)
|
7
7
|
rubyzip (~> 0.9.9)
|
@@ -15,6 +15,8 @@ GEM
|
|
15
15
|
debugger-linecache (~> 1.2.0)
|
16
16
|
columnize (0.3.6)
|
17
17
|
cookiejar (0.3.0)
|
18
|
+
crack (0.4.1)
|
19
|
+
safe_yaml (~> 0.9.0)
|
18
20
|
debugger-linecache (1.2.0)
|
19
21
|
em-http-request (1.1.1)
|
20
22
|
addressable (>= 2.3.4)
|
@@ -25,9 +27,17 @@ GEM
|
|
25
27
|
em-socksify (0.3.0)
|
26
28
|
eventmachine (>= 1.0.0.beta.4)
|
27
29
|
eventmachine (1.0.3)
|
30
|
+
formatador (0.2.4)
|
28
31
|
http_parser.rb (0.6.0.beta.2)
|
29
32
|
minitest (5.0.8)
|
30
33
|
rubyzip (0.9.9)
|
34
|
+
safe_yaml (0.9.7)
|
35
|
+
tach (0.0.8)
|
36
|
+
formatador (>= 0.0.16)
|
37
|
+
vcr (2.6.0)
|
38
|
+
webmock (1.15.0)
|
39
|
+
addressable (>= 2.2.7)
|
40
|
+
crack (>= 0.3.2)
|
31
41
|
|
32
42
|
PLATFORMS
|
33
43
|
ruby
|
@@ -36,3 +46,6 @@ DEPENDENCIES
|
|
36
46
|
byebug
|
37
47
|
em-zipper!
|
38
48
|
minitest
|
49
|
+
tach
|
50
|
+
vcr
|
51
|
+
webmock
|
@@ -0,0 +1,111 @@
|
|
1
|
+
$: << File.expand_path('../lib', __FILE__)
|
2
|
+
require 'rubygems'
|
3
|
+
require 'tach'
|
4
|
+
require 'em-zipper'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
|
8
|
+
sites = %w(http://s3.amazonaws.com/ping-em-assets/sample1.txt http://s3.amazonaws.com/ping-em-assets/sample2.txt)
|
9
|
+
files = %w(sample1.txt sample2.txt).map do |file_name|
|
10
|
+
File.join(File.expand_path("./examples/files"), file_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
Tach.meter(10) do
|
15
|
+
tach('[file] em-zipper') do |n|
|
16
|
+
em_zipper files, n
|
17
|
+
end
|
18
|
+
|
19
|
+
tach('[file] rubyzip') do |n|
|
20
|
+
n.times { |i| rubyzip sites }
|
21
|
+
end
|
22
|
+
|
23
|
+
tach('[net] em-zipper') do |n|
|
24
|
+
em_zipper sites, n
|
25
|
+
end
|
26
|
+
|
27
|
+
tach('[net] rubyzip') do |n|
|
28
|
+
n.times { |i| rubyzip sites }
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def em_zipper(collection, n)
|
33
|
+
EventMachine.run do
|
34
|
+
count = 0
|
35
|
+
|
36
|
+
em_zipper = proc do
|
37
|
+
zip = EM::Zipper.new(collection, StringIO.new).zip!
|
38
|
+
zip.callback do |io|
|
39
|
+
io.close
|
40
|
+
count = count + 1
|
41
|
+
EM.stop if count == n
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
n.times do |i|
|
46
|
+
EM.next_tick(&em_zipper)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def rubyzip(collection)
|
52
|
+
::Zip::ZipOutputStream.write_buffer do |zip|
|
53
|
+
collection.each do |file_path|
|
54
|
+
zip.put_next_entry(File.basename(file_path))
|
55
|
+
|
56
|
+
begin
|
57
|
+
if file_path.match(/\Ahttps?:\/\//)
|
58
|
+
uri = URI file_path
|
59
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
60
|
+
request = Net::HTTP::Get.new uri
|
61
|
+
|
62
|
+
http.request request do |response|
|
63
|
+
response.read_body { |chunk| zip << chunk }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
else
|
67
|
+
file = File.open file_path
|
68
|
+
while chunk = file.read_nonblock(16384)
|
69
|
+
zip << chunk
|
70
|
+
end
|
71
|
+
end
|
72
|
+
rescue EOFError
|
73
|
+
# /
|
74
|
+
ensure
|
75
|
+
file && file.close
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
# //
|
84
|
+
#
|
85
|
+
# File sizes 1.5mb, 503kb
|
86
|
+
#
|
87
|
+
# x10
|
88
|
+
# +------------------+----------+
|
89
|
+
# | tach | total |
|
90
|
+
# +------------------+----------+
|
91
|
+
# | [file] em-zipper | 2.849514 |
|
92
|
+
# +------------------+----------+
|
93
|
+
# | [net] em-zipper | 3.646211 |
|
94
|
+
# +------------------+----------+
|
95
|
+
# | [net] rubyzip | 5.765788 |
|
96
|
+
# +------------------+----------+
|
97
|
+
# | [file] rubyzip | 9.334782 |
|
98
|
+
# +------------------+----------+
|
99
|
+
#
|
100
|
+
# x100
|
101
|
+
# +------------------+-----------+
|
102
|
+
# | tach | total |
|
103
|
+
# +------------------+-----------+
|
104
|
+
# | [file] em-zipper | 27.344414 |
|
105
|
+
# +------------------+-----------+
|
106
|
+
# | [net] em-zipper | 48.246017 |
|
107
|
+
# +------------------+-----------+
|
108
|
+
# | [net] rubyzip | 60.066137 |
|
109
|
+
# +------------------+-----------+
|
110
|
+
# | [file] rubyzip | 66.197528 |
|
111
|
+
# +------------------+-----------+
|
data/examples/file.rb
CHANGED
@@ -20,7 +20,7 @@ EM.run do
|
|
20
20
|
|
21
21
|
# http remotes to file
|
22
22
|
#
|
23
|
-
sites = %w(http://
|
23
|
+
sites = %w(http://s3.amazonaws.com/ping-em-assets/sample1.txt http://s3.amazonaws.com/ping-em-assets/sample2.txt)
|
24
24
|
rbuff = File.new('remotes-file-non-blocking.zip', 'w')
|
25
25
|
rzip = EM::Zipper.new(sites, rbuff)
|
26
26
|
rzip.callback do |io|
|