Skip to content

Commit

Permalink
Merge pull request #5611 from jamshark70/topic/ReaderArgType
Browse files Browse the repository at this point in the history
Classlib: Allow any type of text stream in the FileReader hierarchy
  • Loading branch information
joshpar authored Feb 27, 2022
2 parents f28f98f + 0d60848 commit 03c2799
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions SCClassLibrary/Common/Streams/TabFileReader.sc
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
FileReader : Stream {
// a class to read text files automatically
classvar <delim = $ ; // space separated by default
var <stream, skipEmptyLines=false, skipBlanks=false, <delimiter;
var <stream, skipEmptyLines = false, skipBlanks = false, <delimiter;

*new { | pathOrFile, skipEmptyLines=false, skipBlanks=false, delimiter |
*new { |pathOrFile, skipEmptyLines = false, skipBlanks = false, delimiter|
var stream;
if (pathOrFile.isKindOf(File) ) { stream = pathOrFile } { stream = File(pathOrFile, "r") };
if (stream.isOpen.not) { warn(this.name ++ ": file" + pathOrFile + "not found.") ^nil };
if(pathOrFile.respondsTo(\getChar) ) {
stream = pathOrFile
} {
stream = File(pathOrFile, "r");
if(stream.isOpen.not) {
warn(this.name ++ ": file" + pathOrFile + "not found.");
^nil
};
};
^super.newCopyArgs(stream, skipEmptyLines, skipBlanks, delimiter ? this.delim)
}

reset { stream.reset }

close { stream.close }
// CollStream doesn't implement 'close'
// but is legal to use with readers otherwise
close { stream.tryPerform(\close) }

next {
var c, record, string = String.new;
Expand Down

0 comments on commit 03c2799

Please sign in to comment.