em-zipper 0.0.1
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 +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +38 -0
- data/em-zipper.gemspec +27 -0
- data/examples/file.rb +20 -0
- data/examples/files/sample1.txt +4999 -0
- data/examples/files/sample2.txt +1 -0
- data/examples/io.rb +41 -0
- data/lib/em-zipper/base.rb +72 -0
- data/lib/em-zipper/stream_io.rb +32 -0
- data/lib/em-zipper/zip_output_stream.rb +18 -0
- data/lib/em-zipper.rb +14 -0
- metadata +99 -0
@@ -0,0 +1 @@
|
|
1
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ullamcorper varius leo, sit amet commodo ligula consectetur non. Pellentesque et mauris massa. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed mauris ligula, egestas sit amet suscipit ac, varius vel diam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec luctus sapien at leo lacinia placerat. Integer a auctor mauris.
|
data/examples/io.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
$LOAD_PATH << './lib'
|
2
|
+
require './lib/em-zipper'
|
3
|
+
|
4
|
+
EM.run do
|
5
|
+
EM.add_periodic_timer(1) { puts 'tick' } # tick tock
|
6
|
+
|
7
|
+
files = %w(sample1.txt sample2.txt).map do |file_name|
|
8
|
+
File.join(File.expand_path("./examples/files"), file_name)
|
9
|
+
end
|
10
|
+
|
11
|
+
# zip to IO
|
12
|
+
#
|
13
|
+
buff = StringIO.new
|
14
|
+
|
15
|
+
zippy = EM::Zipper.new files, buff
|
16
|
+
zippy.zip!
|
17
|
+
zippy.callback do |io|
|
18
|
+
|
19
|
+
# Write it out to a file
|
20
|
+
#
|
21
|
+
q = EM::Queue.new
|
22
|
+
file = File.new('io-non-blocking.zip', 'w')
|
23
|
+
|
24
|
+
wf = proc do |chunk|
|
25
|
+
file.write chunk
|
26
|
+
if q.empty?
|
27
|
+
file.close
|
28
|
+
EM.stop
|
29
|
+
else
|
30
|
+
EM.next_tick { q.pop(&wf) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
io.rewind
|
35
|
+
while buffer = io.read(16348)
|
36
|
+
q.push buffer
|
37
|
+
end
|
38
|
+
q.pop(&wf)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'em-http-request'
|
2
|
+
|
3
|
+
module EventMachine
|
4
|
+
module Zipper
|
5
|
+
class Base
|
6
|
+
include EventMachine::Deferrable
|
7
|
+
|
8
|
+
attr_reader :files, :zos, :fqueue
|
9
|
+
|
10
|
+
def initialize(files, zos)
|
11
|
+
@files = files
|
12
|
+
@zos = zos
|
13
|
+
@fqueue = EM::Queue.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def zip!(zip_name=nil)
|
17
|
+
files.each { |file_path| fqueue.push file_path }
|
18
|
+
fqueue.pop(&next_entry_non_block)
|
19
|
+
|
20
|
+
self # ...new(..., ...).zip!
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def file_name(file_path)
|
27
|
+
File.basename file_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def close_zos
|
31
|
+
# zos.close
|
32
|
+
succeed zos.close_buffer # return the zos
|
33
|
+
end
|
34
|
+
|
35
|
+
def next_entry_non_block
|
36
|
+
proc do |file_path|
|
37
|
+
new_entry = ::Zip::ZipEntry.new '-', file_name(file_path)
|
38
|
+
#, "", "", file.size, 0, Zip::ZipEntry::STORED, file.size
|
39
|
+
zos.put_next_entry(new_entry)
|
40
|
+
EM.next_tick { write_entry_non_block file_path }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def write_entry_non_block(file_path)
|
45
|
+
cqueue = EM::Queue.new
|
46
|
+
chunky = proc do |chunk|
|
47
|
+
zos << chunk
|
48
|
+
|
49
|
+
if cqueue.empty?
|
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) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# TODO http requests
|
58
|
+
file_for_non_block file_path, cqueue
|
59
|
+
|
60
|
+
# begin write
|
61
|
+
cqueue.pop(&chunky) if cqueue.size > 0
|
62
|
+
end
|
63
|
+
|
64
|
+
def file_for_non_block(file_path, q)
|
65
|
+
file = File.open file_path
|
66
|
+
while buffer = file.read(16384)
|
67
|
+
q.push buffer
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Provides an IO for http streaming
|
2
|
+
#
|
3
|
+
module EventMachine
|
4
|
+
module Zipper
|
5
|
+
class StreamIO
|
6
|
+
include EventMachine::Deferrable
|
7
|
+
|
8
|
+
def initialize(&block)
|
9
|
+
@block = block
|
10
|
+
@pos = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def tell
|
14
|
+
@pos
|
15
|
+
end
|
16
|
+
|
17
|
+
def pos
|
18
|
+
@pos
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def <<(x)
|
23
|
+
@block.call(x.to_s)
|
24
|
+
@pos += x.to_s.bytesize
|
25
|
+
end
|
26
|
+
|
27
|
+
def each(&block)
|
28
|
+
@block = block
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'zip/zip'
|
2
|
+
|
3
|
+
module EventMachine
|
4
|
+
module Zipper
|
5
|
+
class ZipOutputStream < ::Zip::ZipOutputStream
|
6
|
+
include EventMachine::Deferrable
|
7
|
+
|
8
|
+
def initialize(io)
|
9
|
+
super '-', true
|
10
|
+
@outputStream = io
|
11
|
+
end
|
12
|
+
|
13
|
+
def update_local_headers
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/em-zipper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
|
3
|
+
require 'em-zipper/base'
|
4
|
+
require 'em-zipper/zip_output_stream'
|
5
|
+
require 'em-zipper/stream_io'
|
6
|
+
|
7
|
+
module EventMachine
|
8
|
+
module Zipper
|
9
|
+
def self.new(files, io)
|
10
|
+
Base.new files, ZipOutputStream.new(io)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-zipper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yung Hwa Kwon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubyzip
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.9
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.9
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eventmachine
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: em-http-request
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.1.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.1
|
55
|
+
description: EventMachine wrapped around Rubyzip
|
56
|
+
email:
|
57
|
+
- yung.kwon@damncarousel.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .ruby-gemset
|
63
|
+
- .ruby-version
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- em-zipper.gemspec
|
67
|
+
- examples/file.rb
|
68
|
+
- examples/files/sample1.txt
|
69
|
+
- examples/files/sample2.txt
|
70
|
+
- examples/io.rb
|
71
|
+
- lib/em-zipper.rb
|
72
|
+
- lib/em-zipper/base.rb
|
73
|
+
- lib/em-zipper/stream_io.rb
|
74
|
+
- lib/em-zipper/zip_output_stream.rb
|
75
|
+
homepage: http://github.com/nowk/em-zipper
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.6
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: EventMachine wrapped around Rubyzip
|
99
|
+
test_files: []
|