epitools 0.5.74 → 0.5.75

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/epitools/zopen.rb +18 -11
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa961c91eff30c2d7caa3240c9e13c3357f56ccb
4
- data.tar.gz: 9cb7a50ae1a80cd54305c1c182fa45d1d576f0f6
3
+ metadata.gz: d52d4e8296e7da1393eec498cbaeed20dcb91037
4
+ data.tar.gz: 8d7891b8dc7bce309d07a290559dcec183e49048
5
5
  SHA512:
6
- metadata.gz: 9e51e7eed16a96a82c2ae58589152623157d069f5e7fa096a14985b2cc5a2fb7960ecf3e10ca183ed55c953efd85f3cd414218d514de8800055387fe01b6cf66
7
- data.tar.gz: 31a6dbe284c4c0544a093ce2d2937ca8751bf9f71e241911e0ca65e3536ed2fca4216dd20b42021b7e714190d930465fdc86ccc10a462a2d69ebb940c71df08c
6
+ metadata.gz: 88e37b2e60fa947b5d5a6d4e9d82c105f552fec41139d707f2271e9d7309b3a9be08f2ba8bbbccb0230fa35bddc1bb6d6a16e847b041a977f2ddfc44c8c38756
7
+ data.tar.gz: 6167c8d3cc00215751848926eb1931e036b208d6d7926dc88c45934ed5d9651d1a63a97a911c1ce1f927f0796d69d7b590b3b3f81f908f70c4615b454116ebb8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.74
1
+ 0.5.75
@@ -1,4 +1,10 @@
1
- require 'epitools'
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
- path = Path[path] unless path.is_a? Path
20
- file = path.open(mode)
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
- file = Zlib::GzipReader.new(file)
30
+ io = Zlib::GzipReader.new(io)
26
31
  when "w", "wb"
27
- file = Zlib::GzipWriter.new(file)
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(file)
35
- file.close
41
+ result = yield(io)
42
+ io.close
36
43
  result
37
44
  else
38
- file
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.74
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-02-28 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec