stdioType function
For a stream, returns whether it is attached to a file, pipe, terminal, or something else.
Implementation
StdioType stdioType(object) {
if (object is _StdStream) {
object = object._stream;
} else if (object == stdout || object == stderr) {
int stdiofd = object == stdout ? _stdoutFD : _stderrFD;
switch (_StdIOUtils._getStdioHandleType(stdiofd)) {
case _stdioHandleTypeTerminal:
return StdioType.terminal;
case _stdioHandleTypePipe:
return StdioType.pipe;
case _stdioHandleTypeFile:
return StdioType.file;
}
}
if (object is _FileStream) {
return StdioType.file;
}
if (object is Socket) {
int socketType = _StdIOUtils._socketType(object);
if (socketType == null) return StdioType.other;
switch (socketType) {
case _stdioHandleTypeTerminal:
return StdioType.terminal;
case _stdioHandleTypePipe:
return StdioType.pipe;
case _stdioHandleTypeFile:
return StdioType.file;
}
}
if (object is _IOSinkImpl) {
try {
if (object._target is _FileStreamConsumer) {
return StdioType.file;
}
} catch (e) {
// Only the interface implemented, _sink not available.
}
}
return StdioType.other;
}