X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=code_ruby%2Flib%2Fmaasha%2Ffilesys.rb;h=02a8a842f1157a9824052c589795c1630580ff90;hb=HEAD;hp=4bb7b8f7d17fd4b88b90da6d64a0aa33be527d8d;hpb=2f0fd91b461033529a4a72e161bd133252a22eb6;p=biopieces.git diff --git a/code_ruby/lib/maasha/filesys.rb b/code_ruby/lib/maasha/filesys.rb index 4bb7b8f..02a8a84 100644 --- a/code_ruby/lib/maasha/filesys.rb +++ b/code_ruby/lib/maasha/filesys.rb @@ -22,8 +22,7 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -require 'zlib' -require 'bzip2' +require 'open3' # Error class for all exceptions to do with Filesys. class FilesysError < StandardError; end @@ -49,9 +48,9 @@ class Filesys if mode == 'w' case options[:compress] when :gzip - ios = Zlib::GzipWriter.new File.open(file, mode, options) + ios, = Open3.pipeline_w("gzip -f", out: file) when :bzip, :bzip2 - ios = Bzip2::Writer.new File.open(file, mode, options) + ios, = Open3.pipeline_w("bzip2 -c", out: file) else ios = File.open(file, mode, options) end @@ -59,13 +58,15 @@ class Filesys if file == '-' ios = STDIN else - case `file #{file}` + case `file -Lk #{file}` when /gzip/ - ios = Zlib::GzipReader.new File.open(file, mode, options) + ios = IO.popen("gzip -cd #{file}", :external_encoding=>"EUC-JP") when /bzip/ - ios = Bzip2::Reader.new File.open(file, mode, options) - else + ios = IO.popen("bzcat #{file}") + when /ASCII/ ios = File.open(file, mode, options) + else + raise "Unknown file type: #{`file -L #{file}`}" end end end