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
data/examples/io.rb
CHANGED
@@ -40,7 +40,7 @@ EM.run do
|
|
40
40
|
|
41
41
|
# remote to IO to file
|
42
42
|
#
|
43
|
-
sites = %w(http://
|
43
|
+
sites = %w(http://s3.amazonaws.com/ping-em-assets/sample1.txt http://s3.amazonaws.com/ping-em-assets/sample2.txt)
|
44
44
|
rzip = EM::Zipper.new sites, StringIO.new
|
45
45
|
rzip.callback do |io|
|
46
46
|
write_io_to_file(io, 'io-remote-non-blocking.zip')
|
data/lib/em-zipper/base.rb
CHANGED
@@ -33,42 +33,44 @@ module EventMachine
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def next_entry_non_block
|
36
|
-
proc do |file_path|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
proc do |file_path|
|
37
|
+
cqueue = EM::Queue.new
|
38
|
+
chunky = proc do |chunk|
|
39
|
+
zos << chunk
|
40
|
+
|
41
|
+
if cqueue.empty?
|
42
|
+
close_zos and return if fqueue.empty?
|
43
|
+
EM.next_tick { fqueue.pop(&next_entry_non_block) }
|
44
|
+
else
|
45
|
+
EM.next_tick { cqueue.pop(&chunky) }
|
46
|
+
end
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
defer = EM::DefaultDeferrable.new
|
50
|
+
defer.callback do
|
51
|
+
# begin the entry when we have all the data
|
52
|
+
new_entry = ::Zip::ZipEntry.new '-', file_name(file_path)
|
53
|
+
zos.put_next_entry(new_entry)
|
48
54
|
|
49
|
-
|
50
|
-
close_zos and return if fqueue.empty?
|
51
|
-
EM.next_tick { fqueue.pop(&next_entry_non_block) }
|
52
|
-
else
|
53
|
-
EM.next_tick { cqueue.pop(&chunky) }
|
55
|
+
EM.next_tick { cqueue.pop(&chunky) } if cqueue.size > 0
|
54
56
|
end
|
55
|
-
|
56
|
-
|
57
|
-
defer = EM::DefaultDeferrable.new
|
58
|
-
defer.callback { cqueue.pop(&chunky) if cqueue.size > 0 }
|
57
|
+
defer.errback { puts 'error' }
|
59
58
|
|
60
|
-
|
61
|
-
|
59
|
+
_chunk_method = file_path.match(/\Ahttps?:\/\//) ? :chunk_http : :chunk_file
|
60
|
+
__send__ _chunk_method, file_path, cqueue, defer
|
61
|
+
end
|
62
62
|
end
|
63
63
|
|
64
64
|
def chunk_file(file_path, q, d)
|
65
65
|
file = File.open file_path
|
66
66
|
|
67
67
|
fr = proc do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
begin
|
69
|
+
q.push file.read_nonblock(16384)
|
70
|
+
EM.next_tick(&fr)
|
71
|
+
rescue EOFError
|
72
|
+
file.close
|
73
|
+
EM.next_tick { d.succeed }
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
@@ -77,9 +79,9 @@ module EventMachine
|
|
77
79
|
|
78
80
|
def chunk_http(uri, q, d)
|
79
81
|
http = EventMachine::HttpRequest.new(uri).get
|
80
|
-
http.errback {
|
81
|
-
http.stream { |chunk| q.push chunk }
|
82
|
+
http.errback { EM.next_tick { d.fail } }
|
82
83
|
http.callback { EM.next_tick { d.succeed } }
|
84
|
+
http.stream { |chunk| q.push chunk }
|
83
85
|
end
|
84
86
|
end
|
85
87
|
end
|
data/lib/em-zipper/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-zipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yung Hwa Kwon
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- .ruby-version
|
64
64
|
- Gemfile
|
65
65
|
- Gemfile.lock
|
66
|
+
- benchmarkz/em-zipper.rb
|
66
67
|
- em-zipper.gemspec
|
67
68
|
- examples/async_sinatra.md
|
68
69
|
- examples/file.rb
|