em-files 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +4 -0
- data/VERSION +1 -1
- data/em-files.gemspec +5 -5
- data/lib/em-files.rb +18 -10
- metadata +5 -5
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source "http://rubygems.org"
|
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
4
|
gem "eventmachine", ">= 0.12.10"
|
5
|
-
gem "
|
5
|
+
gem "hash-utils", ">= 0.14.0"
|
6
6
|
|
7
7
|
# Add dependencies to develop your gem here.
|
8
8
|
# Include everything needed to run rake, tests, features, etc.
|
data/Gemfile.lock
CHANGED
@@ -3,11 +3,11 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
eventmachine (0.12.10)
|
5
5
|
git (1.2.5)
|
6
|
+
hash-utils (0.14.0)
|
6
7
|
jeweler (1.5.2)
|
7
8
|
bundler (~> 1.0.0)
|
8
9
|
git (>= 1.2.5)
|
9
10
|
rake
|
10
|
-
multitype-introspection (0.1.2)
|
11
11
|
rake (0.8.7)
|
12
12
|
riot (0.12.2)
|
13
13
|
rr
|
@@ -19,6 +19,6 @@ PLATFORMS
|
|
19
19
|
DEPENDENCIES
|
20
20
|
bundler (~> 1.0.0)
|
21
21
|
eventmachine (>= 0.12.10)
|
22
|
+
hash-utils (>= 0.14.0)
|
22
23
|
jeweler (~> 1.5.2)
|
23
|
-
multitype-introspection (>= 0.1.2)
|
24
24
|
riot (>= 0.12.1)
|
data/README.md
CHANGED
@@ -57,6 +57,10 @@ using filters:
|
|
57
57
|
EM::run do
|
58
58
|
EM::File::write(data, filter) # done in several ticks
|
59
59
|
end
|
60
|
+
|
61
|
+
`#write` supports also copying data from another IO stream because it
|
62
|
+
uses `StringIO` internally. Simply give it IO object instead of
|
63
|
+
`String`. It will read it until EOF will occur.
|
60
64
|
|
61
65
|
|
62
66
|
Contributing
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/em-files.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{em-files}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Martin Kozák"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-25}
|
13
13
|
s.email = %q{martinkozak@martinkozak.net}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
@@ -38,20 +38,20 @@ Gem::Specification.new do |s|
|
|
38
38
|
|
39
39
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
40
|
s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
|
41
|
-
s.add_runtime_dependency(%q<
|
41
|
+
s.add_runtime_dependency(%q<hash-utils>, [">= 0.14.0"])
|
42
42
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
43
43
|
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
44
44
|
s.add_development_dependency(%q<riot>, [">= 0.12.1"])
|
45
45
|
else
|
46
46
|
s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
|
47
|
-
s.add_dependency(%q<
|
47
|
+
s.add_dependency(%q<hash-utils>, [">= 0.14.0"])
|
48
48
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
49
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
50
50
|
s.add_dependency(%q<riot>, [">= 0.12.1"])
|
51
51
|
end
|
52
52
|
else
|
53
53
|
s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
|
54
|
-
s.add_dependency(%q<
|
54
|
+
s.add_dependency(%q<hash-utils>, [">= 0.14.0"])
|
55
55
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
56
56
|
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
57
57
|
s.add_dependency(%q<riot>, [">= 0.12.1"])
|
data/lib/em-files.rb
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
|
4
4
|
require "eventmachine"
|
5
5
|
require "stringio"
|
6
|
-
require "
|
6
|
+
require "hash-utils/io" # >= 0.14.0
|
7
|
+
require "hash-utils/stringio"
|
8
|
+
require "hash-utils/object"
|
7
9
|
|
8
10
|
##
|
9
11
|
# Main EventMachine module.
|
@@ -139,7 +141,7 @@ module EM
|
|
139
141
|
rwsize = self::RWSIZE if rwsize.nil?
|
140
142
|
|
141
143
|
# If filepath is directly IO, uses it
|
142
|
-
if filepath.
|
144
|
+
if filepath.io?
|
143
145
|
@native = filepath
|
144
146
|
else
|
145
147
|
@native = ::File::open(filepath, mode)
|
@@ -229,12 +231,13 @@ module EM
|
|
229
231
|
end
|
230
232
|
|
231
233
|
##
|
232
|
-
# Writes data to file.
|
234
|
+
# Writes data to file. Supports writing both strings or copying
|
235
|
+
# from another IO object.
|
233
236
|
#
|
234
237
|
# It will reopen the file if +EBADF: Bad file descriptor+ of
|
235
|
-
# +File+ class IO object will occur.
|
238
|
+
# +File+ class IO object will occur on +File+ object.
|
236
239
|
#
|
237
|
-
# @param [String] data data for write
|
240
|
+
# @param [String, IO, StringIO] data data for write or IO object
|
238
241
|
# @param [Proc] filter filter which for preprocessing each
|
239
242
|
# written chunk
|
240
243
|
# @param [Proc] block callback called when finish and for giving
|
@@ -242,18 +245,23 @@ module EM
|
|
242
245
|
#
|
243
246
|
|
244
247
|
def write(data, filter = nil, &block)
|
245
|
-
written = 0
|
246
248
|
pos = 0
|
247
249
|
|
250
|
+
if data.io?
|
251
|
+
io = data
|
252
|
+
else
|
253
|
+
io = StringIO::new(data)
|
254
|
+
end
|
255
|
+
|
248
256
|
worker = Proc::new do
|
249
257
|
|
250
258
|
# Writes
|
251
259
|
begin
|
252
|
-
chunk =
|
260
|
+
chunk = io.read(@rw_len)
|
253
261
|
if not filter.nil?
|
254
262
|
chunk = filter.call(chunk)
|
255
263
|
end
|
256
|
-
|
264
|
+
@native.write(chunk)
|
257
265
|
rescue Errno::EBADF
|
258
266
|
if @native.kind_of? File
|
259
267
|
self.reopen!
|
@@ -267,9 +275,9 @@ module EM
|
|
267
275
|
pos = @native.pos
|
268
276
|
|
269
277
|
# Returns or continues work
|
270
|
-
if
|
278
|
+
if io.eof?
|
271
279
|
if not block.nil?
|
272
|
-
block.call(
|
280
|
+
block.call(pos) # returns result
|
273
281
|
end
|
274
282
|
else
|
275
283
|
EM::next_tick { worker.call() } # continues work
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: em-files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "Martin Koz\xC3\xA1k"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-25 00:00:00 +01:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,13 +25,13 @@ dependencies:
|
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: hash-utils
|
29
29
|
requirement: &id002 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.
|
34
|
+
version: 0.14.0
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: *id002
|
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
hash:
|
105
|
+
hash: -2585745239736637618
|
106
106
|
segments:
|
107
107
|
- 0
|
108
108
|
version: "0"
|