File System

The fs module provides an API for interacting with the file system in a manner closely modeled around standard POSIX functions.

Goal of this inerface is to be compatible with Node.js File System API

Compatibility objective : 80%

To use this module:

const fs = require('fs');

All file system operations have synchronous and asynchronous forms.

fs.readFile(path)

Compatibility : broken

Open, read and return text content of a file. It will throw an exception if it fails.

  • path <string> Path of the file to read from
  • Returns : Contents of the file
let data = fs.readFile('/etc/passwd');
console.info('Data : {0}', data);

fs.readdirSync(path, options)

Synchronous readdir(3).

  • path <string> Path of the directory
  • options <object> Options
  • Returns : An array of filenames excluding ‘.’ and ‘..’

fs.statSync(path)

Synchronous stat(2). Returns an instance of fs.Stats.

Class : fs.Stats

A fs.Stats object provides information about a file.

stats.isDirectory()

Returns true if the fs.Stats object describes a file system directory.

stats.isFile()

Returns true if the fs.Stats object describes a regular file.

Returns true if the fs.Stats object describes a symbolic link.

stats.dev

  • <number> The numeric identifier of the device containing the file.

stats.ino

  • <number> The file system specific “Inode” number for the file.

stats.mode

  • <number> A bit-field describing the file type and mode.
  • <number> The number of hard-links that exist for the file.

stats.uid

  • <number> The numeric user identifier of the user that owns the file (POSIX).

stats.size

  • <number> The size of the file in bytes.

stats.blksize

  • <number> The number of blocks allocated for this file.

TODO

  • Add support for Promises
  • Fix broken API