epitools 0.5.74 → 0.5.75
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/epitools/zopen.rb +18 -11
- 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: d52d4e8296e7da1393eec498cbaeed20dcb91037
|
4
|
+
data.tar.gz: 8d7891b8dc7bce309d07a290559dcec183e49048
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88e37b2e60fa947b5d5a6d4e9d82c105f552fec41139d707f2271e9d7309b3a9be08f2ba8bbbccb0230fa35bddc1bb6d6a16e847b041a977f2ddfc44c8c38756
|
7
|
+
data.tar.gz: 6167c8d3cc00215751848926eb1931e036b208d6d7926dc88c45934ed5d9651d1a63a97a911c1ce1f927f0796d69d7b590b3b3f81f908f70c4615b454116ebb8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.75
|
data/lib/epitools/zopen.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'zlib'
|
2
|
+
|
3
|
+
COMPRESSORS = {
|
4
|
+
".gz" => "gzip",
|
5
|
+
".xz" => "xz",
|
6
|
+
".bz2" => "bzip2"
|
7
|
+
}
|
2
8
|
|
3
9
|
#
|
4
10
|
# A mutation of "open" that lets you read/write gzip files, as well as
|
@@ -15,27 +21,28 @@ require 'epitools'
|
|
15
21
|
# zopen("test.txt.gz") { |f| f.read } # read the contents of the .gz file, then close the file handle automatically.
|
16
22
|
#
|
17
23
|
def zopen(path, mode="rb")
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if path.ext == "gz"
|
24
|
+
ext = File.extname(path).downcase
|
25
|
+
|
26
|
+
if ext == ".gz"
|
27
|
+
io = open(path, mode)
|
23
28
|
case mode
|
24
29
|
when "r", "rb"
|
25
|
-
|
30
|
+
io = Zlib::GzipReader.new(io)
|
26
31
|
when "w", "wb"
|
27
|
-
|
32
|
+
io = Zlib::GzipWriter.new(io)
|
28
33
|
else
|
29
34
|
raise "Unknown mode: #{mode.inspect}. zopen only supports 'r' and 'w'."
|
30
35
|
end
|
36
|
+
elsif bin = COMPRESSORS[ext]
|
37
|
+
io = IO.popen([bin, "-d" ,"-c", path])
|
31
38
|
end
|
32
39
|
|
33
40
|
if block_given?
|
34
|
-
result = yield(
|
35
|
-
|
41
|
+
result = yield(io)
|
42
|
+
io.close
|
36
43
|
result
|
37
44
|
else
|
38
|
-
|
45
|
+
io
|
39
46
|
end
|
40
47
|
|
41
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.75
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|