FileSystem Class

Module: Files

FileSystem is used to read and write files using nunuStudio.

Some operations are platform specific and might not work everywhere.

Methods

chooseFile

(
  • onLoad
  • filter
  • saveas
)

Open file chooser dialog receives onLoad callback, file filter, saveas.

Save mode does not work inside the browser.

The onLoad callback receives as array of files as parameter.

Parameters:

  • onLoad Function

    onLoad callback that receives array of files choosen as parameter

  • filter String

    File type filter

  • saveas String

    Save as format can be also a boolean value

chooseFileName

(
  • onLoad
  • saveas
)

Used as an alternative to chooseFile for saving files in the browser.

Uses a prompt to question the user the file name.

Parameters:

  • onLoad Function

    onLoad callback

  • saveas String

    File extension

copyFile

(
  • src
  • dst
)

Copy file (cannot be used to copy folders).

Only works when running inside NWJS.

Parameters:

  • src String
  • dst String

copyFolder

(
  • src
  • dst
)

Copy folder and all its files (includes symbolic links).

Only works when running inside NWJS.

Parameters:

  • src String
  • dst String

fileExists

(
  • file
)
Boolean

Check if a file exists.

Only works inside of NWJS. When running inside the browser always returns false.

Parameters:

  • file String

    File path

Returns:

Boolean:

True is file exists

getFileExtension

(
  • file
)
String

Get file extension from file path string (always in lowercase).

If input is a/b/c/abc.d output is d.

Parameters:

  • file String

    File path

Returns:

String:

getFileName

(
  • file
)
String

Get file name without extension from file path string.

If input is a/b/c/abc.d output is abc.

Parameters:

  • file String

    File path

Returns:

String:

File name without path and extension

getFilePath

(
  • file
)
String

Get file directoty.

If input is a/b/c/abc.d output is a/b/c/

Parameters:

  • file String

    File path

Returns:

String:

getFilesDirectory

() Array

Returns files in directory (returns empty array in case of error).

Only works when running inside NWJS.

Returns:

Array:

Files in the directory

getNameWithoutExtension

(
  • file
)
String

Get file name without extension.

If input is a/b/c/abc.d output is a/b/c/abc.

Parameters:

  • file String

    File path

Returns:

String:

makeDirectory

(
  • dir
)

Make a directory (dont trow exeption if directory already exists).

Only works when running inside NWJS.

Parameters:

  • dir String

readFile

(
  • fname
  • sync
  • onLoad
  • onProgress
)
String

Read file content as text.

Parameters:

  • fname String

    URL to the file.

  • sync Boolean

    If true the file will be read in sync.

  • onLoad Function

    onLoad callback.

  • onProgress Function

    onProgress callback.

Returns:

String:

File content as a string, null if reading async.

readFileArrayBuffer

(
  • fname
  • sync
  • onLoad
  • onProgress
)
ArrayBuffer

Read file as arraybuffer data.

Parameters:

  • fname String

    Name of the file

  • sync Boolean

    If true the file will be read in sync.

  • onLoad Function

    onLoad callback.

  • onProgress Function

    onProgress callback.

Returns:

ArrayBuffer:

File data as array buffer, null on error

readFileBase64

(
  • fname
  • sync
  • onLoad
  • onProgress
)
String

Read file as base64 data.

Parameters:

  • fname String

    Name of the file

  • sync Boolean

    If true the file will be read in sync.

  • onLoad Function

    onLoad callback.

  • onProgress Function

    onProgress callback.

Returns:

String:

File data in base64, null on error

writeFile

(
  • fname
  • data
)

Write text file.

When running without NWJS it writes file as a blob and auto downloads it.

Parameters:

  • fname String

    File name.

  • data String

    Text to be written to the file.

writeFileArrayBuffer

(
  • fname
  • data
)

Write binary file using arraybuffer data.

Parameters:

  • fname String
  • data String

writeFileBase64

(
  • fname
  • data
)

Write binary file using base64 data.

Parameters:

  • fname String
  • data String