FileSystem Class
FileSystem is used to read and write files using nunuStudio.
Its implements multiple solutions for each method depending on the platform (NodeJS, brower or cordova).
Some operations are platform specific and might not work everywhere.
Item Index
Methods
- chooseDirectory
- chooseFile
- chooseFileName
- chooseFileWrite
- copyFile
- copyFolder
- deleteFolder
- fileExists
- getFileExtension
- getFileName
- getFileNameWithExtension
- getFilePath
- getFilesDirectory
- getNameWithoutExtension
- isLocalFile
- makeDirectory
- readFile
- readFileArrayBuffer
- readFileBase64
- writeFile
- writeFileArrayBuffer
- writeFileBase64
Methods
chooseDirectory
()
PromiseOpen file chooser dialog window for the user to select a directory.
Only works while using NWJS.
Returns:
Promise that resolves with the selected path.
chooseFile
-
onLoad
-
filter
-
saveas
-
multiFile
Open file chooser dialog window for the user to select files stored in the system.
The files selected are retrieved using the onLoad callback that receives a array of File objects.
Parameters:
-
onLoad
FunctiononLoad callback that receives array of files as parameter.
-
filter
StringFile type filter (e.g. .zip, .rar).
-
saveas
StringFile format or name to be used, optinonally it can be a boolean value indicating savemode.
-
multiFile
BooleanIf true the chooser will accept multiple files.
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
FunctiononLoad callback
-
saveas
StringFile extension
chooseFileWrite
-
onLoad
-
filter
Choose a file path/name to create a new file and write it to the system.
Depending on the platform opens a file path selection windows of a box to select the name of the file.
Parameters:
-
onLoad
FunctiononLoad callback that receives the path select to write the file.
-
filter
StringFile type filter (e.g. ".zip,.rar").
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
deleteFolder
-
path
Delete folders and all subfolders.
Only works when running inside NWJS.
Parameters:
-
path
String
fileExists
-
file
Check if a file exists.
Only works inside of NWJS. When running inside the browser always returns false.
Parameters:
-
file
StringFile path
Returns:
True is file exists
getFileExtension
-
file
Get file extension from file path string (always in lowercase).
If input is a/b/c/abc.d output is d.
Parameters:
-
file
StringFile path
Returns:
getFileName
-
file
Get file name without extension from file path string.
If input is a/b/c/abc.d output is abc.
Parameters:
-
file
StringFile path
Returns:
File name without path and extension
getFileNameWithExtension
-
file
Get file name with extension from file path string.
If input is a/b/c/abc.d output is abc.d.
Parameters:
-
file
StringFile path
Returns:
File name without path with extension
getFilePath
-
file
Get directory where the file is placed.
If input is a/b/c/abc.d output is a/b/c/
Parameters:
-
file
StringFile path
Returns:
getFilesDirectory
()
Array
Returns files in directory (returns empty array in case of error).
Only works when running inside NWJS.
Returns:
Files in the directory
getNameWithoutExtension
-
file
Get file name without extension.
If input is a/b/c/abc.d output is a/b/c/abc.
Parameters:
-
file
StringFile path
Returns:
isLocalFile
()
Boolean
Check if a file corresponds to a remote location.
Returns:
If the file is remote returns true, false otherwise.
makeDirectory
-
dir
Make a directory (dont throw exeption if directory already exists).
Only works when running inside NWJS.
Parameters:
-
dir
String
readFile
-
fname
-
sync
-
onLoad
-
onProgress
-
onError
Read a local or remote file as text data.
When running on desktop uses nodejs to access files, on the web performs a http GET request.
Parameters:
-
fname
StringPath or URL of the file being read.
-
sync
BooleanIf true the file will be read in sync.
-
onLoad
FunctiononLoad callback receives the read data as parameter.
-
onProgress
FunctiononProgress callback used to check the file reading progress.
-
onError
FunctiononError call is called when a error occurs while reading the file.
Returns:
File text, or null if the request is async.
readFileArrayBuffer
-
fname
-
sync
-
onLoad
-
onProgress
-
onError
Read a local or remote file as arraybuffer data.
When running on desktop uses nodejs to access files, on the web performs a http GET request.
Parameters:
-
fname
StringPath or URL of the file being read.
-
sync
BooleanIf true the file will be read in sync.
-
onLoad
FunctiononLoad callback receives the read data as parameter.
-
onProgress
FunctiononProgress callback used to check the file reading progress.
-
onError
FunctiononError call is called when a error occurs while reading the file.
Returns:
File data as array buffer, or null if the request is async.
readFileBase64
-
fname
-
sync
-
onLoad
-
onProgress
-
onError
Read a local or remote file as base64 data.
When running on desktop uses nodejs to access files, on the web performs a http GET request.
Parameters:
-
fname
StringPath or URL of the file being read.
-
sync
BooleanIf true the file will be read in sync.
-
onLoad
FunctiononLoad callback receives the read data as parameter.
-
onProgress
FunctiononProgress callback used to check the file reading progress.
-
onError
FunctiononError call is called when a error occurs while reading the file.
Returns:
File data as base64, or null if the request is async.
writeFile
-
fname
-
data
-
sync
-
onFinish
Write text to a file.
When running on the web it writes file to a blob and auto downloads it.
Parameters:
-
fname
StringName/path of the file to write.
-
data
StringText to be written to the file.
-
sync
BooleanIf true the file is written syncronously. (Only available for Nodejs).
-
onFinish
FunctionCallback function called when the file is written.
writeFileArrayBuffer
-
fname
-
data
-
sync
-
onFinish
Write binary file using arraybuffer data.
If running on the web writes the file into a blob and auto downloads it.
Parameters:
-
fname
StringName/path of the file to write.
-
data
StringArraybuffer data to be written into the file.
-
sync
BooleanIf true the file is written syncronously. (Only available for Nodejs)
-
onFinish
FunctionCallback function called when the file is written.
writeFileBase64
-
fname
-
data
-
sync
-
onFinish
Write binary file using base64 data.
If running on the web writes the file into a blob and auto downloads it.
Parameters:
-
fname
StringName/path of the file to write.
-
data
StringBase64 data to be written into the file.
-
sync
BooleanIf true the file is written syncronously. (Only available for Nodejs)
-
onFinish
FunctionCallback function called when the file is written.