@ezdevlol/memfs
Version:
In-memory file-system with Node's fs API.
47 lines (46 loc) • 1.27 kB
JavaScript
import { constants } from './constants';
import { strToEncoding } from './encoding';
const { S_IFMT, S_IFDIR, S_IFREG, S_IFBLK, S_IFCHR, S_IFLNK, S_IFIFO, S_IFSOCK } = constants;
/**
* A directory entry, like `fs.Dirent`.
*/
export class Dirent {
static build(link, encoding) {
const dirent = new Dirent();
const { mode } = link.getNode();
dirent.name = strToEncoding(link.getName(), encoding);
dirent.mode = mode;
dirent.path = link.getParentPath();
dirent.parentPath = dirent.path;
return dirent;
}
name = '';
path = '';
parentPath = '';
mode = 0;
_checkModeProperty(property) {
return (this.mode & S_IFMT) === property;
}
isDirectory() {
return this._checkModeProperty(S_IFDIR);
}
isFile() {
return this._checkModeProperty(S_IFREG);
}
isBlockDevice() {
return this._checkModeProperty(S_IFBLK);
}
isCharacterDevice() {
return this._checkModeProperty(S_IFCHR);
}
isSymbolicLink() {
return this._checkModeProperty(S_IFLNK);
}
isFIFO() {
return this._checkModeProperty(S_IFIFO);
}
isSocket() {
return this._checkModeProperty(S_IFSOCK);
}
}
export default Dirent;