Skip to content

Add fs.typeof method #11

@aleclarson

Description

@aleclarson

It returns the path type according to its on-disk representation.

Possible results include: file, directory, symlink, socket, fifo, characterDevice, blockDevice

// The path argument may be absolute or relative to the root directory.
fs.typeof('foo')

The best use case for this is a switch statement.

switch (fs.typeof(path)) {
  case 'file': 
    // ...
    break

  case 'directory':
    // ...
    break

  default:
    throw new Error('unsupported file type')
}

This is better than using fs.stat or fs.lstat, because change events don't need to be watched for like they do with those methods. Just need to use the existenceWatcher, I think.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions