summaryrefslogtreecommitdiff
path: root/lib/nlp_ruby/fileutil.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nlp_ruby/fileutil.rb')
-rw-r--r--lib/nlp_ruby/fileutil.rb88
1 files changed, 0 insertions, 88 deletions
diff --git a/lib/nlp_ruby/fileutil.rb b/lib/nlp_ruby/fileutil.rb
deleted file mode 100644
index eb69136..0000000
--- a/lib/nlp_ruby/fileutil.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-require 'zlib'
-
-
-class ReadFile
-
- def initialize fn, encoding='utf-8'
- if fn.split('.').last == 'gz'
- @f = Zlib::GzipReader.new(File.new(fn, 'rb'), :external_encoding=>encoding)
- elsif fn == '-'
- @f = STDIN
- STDIN.set_encoding encoding
- else
- @f = File.new fn, 'r'
- @f.set_encoding encoding
- end
- end
-
- def gets
- @f.gets { |line| yield line }
- end
-
- def readlines
- @f.readlines
- end
-
- def self.readlines fn, encoding='utf-8'
- f = ReadFile.new fn, encoding
- r = f.readlines
- f.close
- return r
- end
-
- def readlines_strip
- self.readlines.map{ |i| i.strip }
- end
-
- def self.readlines_strip fn, encoding='utf-8'
- f = ReadFile.new fn, encoding
- r = f.readlines_strip
- f.close
- return r
- end
-
- def read
- @f.read
- end
-
- def self.read fn, encoding='utf-8'
- f = ReadFile.new fn, encoding
- r = f.read
- f.close
- return r
- end
-
- def close
- @f.close if @f!=STDIN
- end
-end
-
-class WriteFile
-
- def initialize fn, encoding='utf-8'
- if fn.split('.').last == 'gz'
- @f = Zlib::GzipWriter.new(File.new(fn, 'wb+'), :external_encoding=>encoding)
- elsif fn == '-'
- @f = STDOUT
- STDOUT.set_encoding encoding
- else
- @f = File.new fn, 'w+'
- @f.set_encoding encoding
- end
- end
-
- def write s
- @f.write s
- end
-
- def self.write s, fn, encoding='utf-8'
- f = WriteFile.new fn, encoding
- f.write s
- f.close
- end
-
- def close
- @f.close if @f!=STDIN
- end
-end
-