stdioType function

StdioType stdioType(object)

For a stream, returns whether it is attached to a file, pipe, terminal, or something else.

Source

StdioType stdioType(object) {
  if (object is _StdStream) {
    object = object._stream;
  } else if (object == stdout || object == stderr) {
    switch (_StdIOUtils._getStdioHandleType(object == stdout ? 1 : 2)) {
      case _STDIO_HANDLE_TYPE_TERMINAL:
        return StdioType.TERMINAL;
      case _STDIO_HANDLE_TYPE_PIPE:
        return StdioType.PIPE;
      case _STDIO_HANDLE_TYPE_FILE:
        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 _STDIO_HANDLE_TYPE_TERMINAL:
        return StdioType.TERMINAL;
      case _STDIO_HANDLE_TYPE_PIPE:
        return StdioType.PIPE;
      case _STDIO_HANDLE_TYPE_FILE:
        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;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-io/stdioType.html