fs

UnityBase file-system routines. We try to implement here the same interface as in NodeJS fs

 var fs = require('fs');
 var content = fs.readFileSync('c:\\a.txt');

Methods

isFile(path)Boolean static

Check specified path is file (or symlynk to file)
Arguments:
  1. path

isDir(path)Boolean static

Check specified path is folder (or symlynk to folder)
Arguments:
  1. path

loadFile(fileName, forceUFT8opt)String static

Reads the entire contents of a TEXT file. If BOM found - decode text file to string using BOM If BOM not found - use forceUFT8 parameter.
Arguments:
  1. fileName (String)
  2. [forceUFT8] (Boolean)  If no BOM found and forceUFT8 is True (default) - we expect file in UTF8 format, else in ascii

readFileSync(fileName, optionsopt)String|ArrayBuffer static

Reads the entire contents of a file. If options.encoding == 'bin', then the ArrayBuffer is returned. If no options is specified at all - result is String as in fs.loadFile
Arguments:
  1. fileName (String)  Absolute path to file
  2. [options] (Object)
    Properties
    1. [encoding] (String|Null)  Default to null. Possible values: 'bin'|'ascii'|'utf-8'

mkdirSync(path, modeopt) static

Create all missing folders in the given path. Only absolute path supported. Throw error in case of fail
Arguments:
  1. path (String)  path for creation.
  2. [mode] (Number)  Ignored under Windows

readdirSync(path) → Array:.<String:> static

Read file names from directory (include folder names). Return array of file names. In case directory not exists - throw error
Arguments:
  1. path (String)

statSync(fileName)Boolean|Object static

Get file statistics. Return false in case file or folder dose not exists.
Arguments:
  1. fileName

writeFileSync(fileName, data, optionsopt) static

Write to file Actually implements UBWriter#write
Arguments:
  1. fileName (String)  Full absolute file path
  2. data (ArrayBuffer|Object|String)  Data to write. If Object - it stringify before write
  3. [options] (Object)
    Properties
    1. [encoding] (String)  Encode data to encoding before write. Default to utf-8 in case data is String or bin in case data is ArrayBuffer. One of "utf-8"|"ucs2"|"bin"|"base64".

appendFileSync(fileName, data, optionsopt) static

Append data to a file, creating the file if it not yet exists Actually implement {UBWriter#write}
Arguments:
  1. fileName (String)  Full absolute file path
  2. data (ArrayBuffer|Object|String)  Data to write. Object are stringified before write
  3. [options] (Object)
    Properties
    1. [encoding] (String)  Encode data to encoding before write. Default to utf-8 in case data is String or bin in case data is ArrayBuffer. Possible values: "utf-8"|"ucs2"|"bin"|"base64".

existsSync(path)Boolean static

Check path exists (can be file, folder or symlync)
Arguments:
  1. path

unlinkSync() static

Delete file.

rmdirSync(path) static

Delete non-empty directory. See removeDir for details
Arguments:
  1. path (String)  path to remove

renameSync(oldPath, newPath) static

Move (rename) file.
Arguments:
  1. oldPath (String)
  2. newPath (String)