cat function
Concatenates files in paths
to the standard output or a file.
output
should be an IOSink such as stdout or File.openWrite.input
can be stdin.
The remaining optional parameters are similar to the GNU cat utility.
Implementation
Future<CatResult> cat(List<String> paths, IOSink output,
{Stream<List<int>>? input,
bool numberNonBlank = false,
bool showEnds = false,
bool showLineNumbers = false,
bool showNonPrinting = false,
bool showTabs = false,
bool squeezeBlank = false}) async {
final result = CatResult();
final lastLine = _LastLine();
if (paths.isEmpty) {
if (input != null) {
try {
await _copyStream(input, lastLine, output, numberNonBlank, showEnds,
showLineNumbers, showNonPrinting, showTabs, squeezeBlank);
} catch (e) {
result.addError(_getErrorMessage(e));
}
}
} else {
for (final path in paths) {
try {
final Stream<List<int>> stream;
if (path == '-' && input != null) {
stream = input;
} else {
stream = File(path).openRead();
}
await _copyStream(stream, lastLine, output, numberNonBlank, showEnds,
showLineNumbers, showNonPrinting, showTabs, squeezeBlank);
} catch (e) {
result.addError(_getErrorMessage(e), path: path);
}
}
}
return result;
}