1 # Copyright (C) 2007-2011 Martin A. Hansen.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # http://www.gnu.org/copyleft/gpl.html
19 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
21 # This software is part of the Biopieces framework (www.biopieces.org).
23 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
27 # Error class for all exceptions to do with Filesys.
28 class FilesysError < StandardError; end
33 # Class method that returns a path to a unique temporary file.
34 # If no directory is specified reverts to the systems tmp directory.
35 def self.tmpfile(tmp_dir = ENV["TMPDIR"])
39 path = tmp_dir + [user, time + pid, pid].join("_") + ".tmp"
43 # Class method allowing open to be used on (zipped) files.
52 ios = self.new(File.open(*args))
54 ios = self.zopen(*args)
72 # Method to close ios.
74 @io.close unless @io.is_a? Zlib::GzipReader
81 # Method to check if io is closed.
86 # Iterator method for parsing entries.
88 while entry = get_entry do
93 # Method to puts directoy on Filesys objects.
100 # Helper method to return an ios to a file that may be zipped in which case
101 # the ios is unzipped on the fly. See File.open.
102 def self.zopen(*args)
103 ios = File.open(*args)
106 ios = Zlib::GzipReader.new(ios)