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
- chooseFile
- chooseFileName
- chooseFileWrite
- copyFile
- copyFolder
- deleteFolder
- fileExists
- getFileExtension
- getFileName
- getFileNameWithExtension
- getFilePath
- getFilesDirectory
- getNameWithoutExtension
- isLocalFile
- makeDirectory
- readFile
- readFileArrayBuffer
- readFileBase64
- writeFile
- writeFileArrayBuffer
- writeFileBase64
Methods
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:
-
onLoadFunctiononLoad callback that receives array of files as parameter.
-
filterStringFile type filter (e.g. ".zip,.rar, etc)
-
saveasStringFile format or name to be used, optinonally it can be a boolean value indicating savemode.
-
multiFileBooleanIf 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:
-
onLoadFunctiononLoad callback
-
saveasStringFile 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:
-
onLoadFunctiononLoad callback that receives the path select to write the file.
-
filterStringFile type filter (e.g. ".zip,.rar, etc).
copyFile
-
src -
dst
Copy file (cannot be used to copy folders).
Only works when running inside NWJS.
Parameters:
-
srcString -
dstString
copyFolder
-
src -
dst
Copy folder and all its files (includes symbolic links).
Only works when running inside NWJS.
Parameters:
-
srcString -
dstString
deleteFolder
-
path
Delete folders and all subfolders.
Only works when running inside NWJS.
Parameters:
-
pathString
fileExists
-
file
Check if a file exists.
Only works inside of NWJS. When running inside the browser always returns false.
Parameters:
-
fileStringFile 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:
-
fileStringFile 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:
-
fileStringFile 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:
-
fileStringFile 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:
-
fileStringFile 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:
-
fileStringFile 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:
-
dirString
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:
-
fnameStringPath or URL of the file being read.
-
syncBooleanIf true the file will be read in sync.
-
onLoadFunctiononLoad callback receives the read data as parameter.
-
onProgressFunctiononProgress callback used to check the file reading progress.
-
onErrorFunctiononError 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:
-
fnameStringPath or URL of the file being read.
-
syncBooleanIf true the file will be read in sync.
-
onLoadFunctiononLoad callback receives the read data as parameter.
-
onProgressFunctiononProgress callback used to check the file reading progress.
-
onErrorFunctiononError 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:
-
fnameStringPath or URL of the file being read.
-
syncBooleanIf true the file will be read in sync.
-
onLoadFunctiononLoad callback receives the read data as parameter.
-
onProgressFunctiononProgress callback used to check the file reading progress.
-
onErrorFunctiononError 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:
-
fnameStringName/path of the file to write.
-
dataStringText to be written to the file.
-
syncBooleanIf true the file is written syncronously. (Only available for Nodejs).
-
onFinishFunctionCallback 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:
-
fnameStringName/path of the file to write.
-
dataStringArraybuffer data to be written into the file.
-
syncBooleanIf true the file is written syncronously. (Only available for Nodejs)
-
onFinishFunctionCallback 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:
-
fnameStringName/path of the file to write.
-
dataStringBase64 data to be written into the file.
-
syncBooleanIf true the file is written syncronously. (Only available for Nodejs)
-
onFinishFunctionCallback function called when the file is written.
