Working with Files
Structure
Files & folders in win32.run shared the same structure. I'm not good at naming, let's call them fs_item
To get a fs_item from id
Each fs_item is identified with an id. Here's the general structure of a fs_item
Operations
It's recommended that you use $lib/fs.js
instead of working with files manually.
When I wrote this fs.js file, I didn't intend for its functions to be used by another human being, so it's pretty messed up there, without any code comments. Shame on me.
Create
This function creates a new fs_item (can create both file and folder), returns a promise that resolves with the newly created fs_item id.
type: String
: can be 'file
' to create a new file, or 'folder
' to create a new folderext: String:
thefs_item
extension, start with a dot. e.g: .jpg, .png. Leave an empty string''
iftype == 'folder'
seedname: String:
suggested file name. e.g: 'nevada desert'.
parent_id: String:
id of the parent folder where the newly created item will be located.file: File:
the actually file content. See Mozilla Docs
Copy
To actually copy a fs_item, use fs.clone_fs()
item_id: String
: the fs_item id that you want to copynew_parent_id: String
: id of the destination directory (folder)new_item_id: String
: provide the newly created item an id so you can refer to it later. Sorry for this inconvenience.
To generate an id:
Note: The fs.copy
, fs.cut
functions are used to put an item into the clipboard. These functions don't actually copy or cut an item.
Delete
To permanently delete a fs_item
Save
To save content to a fs_item
In which file
is the new content as a File object. See Mozilla Docs
Example:
Read
To read content of a fs_item, use fs.get_file(item_id)
. This function returns a promise that resolves with a File object. See Mozilla Docs.
fs_item's id to human-readable path
If you have a fs_item's id (e.g. 1Ggc8cPyxmAqp5tqKdo3s9
) and want to convert it into a human-readable path like what is being displayed in My Computer D:\webpages\any_name.html
human-readable path to fs_item id
If you have path (for example D:\webpages\any_name.html
) and want to get the fs_item id out of it
Last updated