====== Javascript binding API - Eio - File and directory management ======
[[api:javascript|Back to the JS EFL page]]
The Eio module provides functions to work with file and directories, allowing a finer control over them with monitors and callbacks during the operations, while Ecore provides simple wrappers over the console commands.
==== Constants ====
=== File operations ===
These constants represent the operations that can be done on files and directories.
* ''efl.Eio.FILE_COPY'' - I/O operation is about a specific file copy.
* ''efl.Eio.FILE_MOVE'' - I/O operation is about a specific file move.
* ''efl.Eio.DIR_COPY'' - I/O operation is about a specific directory copy.
* ''efl.Eio.DIR_MOVE'' - I/O operation is about a specific directory move.
* ''efl.Eio.UNLINK'' - I/O operation is about destroying a path: source will point to base path to be destroyed, and dest will point to to ath destroyed by this I/O.
* ''efl.Eio.FILE_GETPWNAM'' - I/O operation is trying to get uid from user name.
* ''efl.Eio.FILE_GETGRNAM'' - I/O operation is trying to get gid from user name.
=== Monitoring constants ===
* ''efl.Eio.MONITOR_FILE_CREATED'' - New file created in a watched directory.
* ''efl.Eio.MONITOR_FILE_DELETED'' - Watched file or file in watched directory was deleted.
* ''efl.Eio.MONITOR_FILE_MODIFIED'' - File modified in a watched directory.
* ''efl.Eio.MONITOR_FILE_CLOSED'' - File closed in a watched directory.
* ''efl.Eio.MONITOR_DIRECTORY_CREATED'' - New directory created in a watched directory.
* ''efl.Eio.MONITOR_DIRECTORY_DELETED'' - A directory has been deleted: this can be either a watched directory or one of its subdirectories.
* ''efl.Eio.MONITOR_DIRECTORY_MODIFIED'' - A directory has been modified in a watched directory.
* ''efl.Eio.MONITOR_DIRECTORY_CLOSED'' - A directory has been closed in a watched directory.
* ''efl.Eio.MONITOR_SELF_RENAME'' - The monitored path has been renamed, an error could happen just after if the renamed path doesn't exist.
* ''efl.Eio.MONITOR_SELF_DELETED'' - The monitored path has been removed.
* ''efl.Eio.MONITOR_ERROR'' - During operation the monitor failed and will no longer work.
This function will add the given path to its internal list of files to monitor. It utilizes the inotify mechanism introduced in kernel 2.6.13 for passive monitoring.
These functions use the best available method to monitor changes on a specified directory or file. They send ecore events when changes occur, and they maintain internal refcounts to reduce resource consumption on duplicate monitor targets.
var operation = efl.Eio.copyDir(source, dest, filter_cb, progress_cb, done_cb, error_cb);
</code>
Parameters
* path - Should be the name of the directory to move the data from.
* dest - Should be the name of the directory to move the data to.
* filter_cb - Possible to deny the move of some files/directories.
* progress_cb - Callback called to know the progress of the move.
* done_cb - Callback called when the operation is completed.
* error_cb - Callback called from if something goes wrong.
Return value
* object - A reference to the I/O operation as an Eio File object.
Move a directory and its content asynchronously.
This function will copy a directory and all its content from source to dest. It will try to use splice if possible, if not it will fallback to mmap/write. It will try to preserve access rights, but not user/group identity. Every file will be passed to the filter_cb, so it's your job to decide if you want to pass the file to the main_cb or not. Return ''true'' to pass it to the main_cb or ''false'' to ignore it.
The ''progress_cb'' receives the same arguments as its ''efl.Eio.moveFile()'' counterpart.
The ''filter_cb'' is called for each member of the directory and receives as argument the Eio File operation handle and the directory entry information, the latter as an object with the following keys:
var operation = efl.Eio.copyFile(source, dest, progress_cb, done_cb, error_cb);
</code>
Parameters
* path - Should be the name of the file to copy the data from.
* dest - Should be the name of the file to copy the data to.
* progress_cb - Callback called to know the progress of the copy.
* done_cb - Callback called when the operation is completed.
* error_cb - Callback called from if something goes wrong.
Return value
* object - A reference to the I/O operation as an Eio File object.
This function will copy a file from source to dest. It will try to use splice if possible, if not it will fallback to mmap/write. It will try to preserve access rights, but not user/group identification.
The ''info'' argument to ''progress_cb'' is an object with the following keys:
* ''op'' - The operation being worked on.
* ''current'' - Current step in the I/O operation.
This function is responsible for listing the content of a directory without blocking your application. It's equivalent to the "ls" shell command. Every file will be passed to the filter_cb, so it's your job to decide if you want to pass the file to the main_cb or not. Return ''true'' to pass it to the ''main_cb'' or ''false'' to ignore it. It runs the native ''eina_file_ls()'' on a separate thread.
var operation = efl.Eio.moveDir(source, dest, filter_cb, progress_cb, done_cb, error_cb);
</code>
Parameters
* path - Should be the name of the directory to move the data from.
* dest - Should be the name of the directory to move the data to.
* filter_cb - Possible to deny the move of some files/directories.
* progress_cb - Callback called to know the progress of the move.
* done_cb - Callback called when the operation is completed.
* error_cb - Callback called from if something goes wrong.
Return value
* object - A reference to the I/O operation as an Eio File object.
Move a directory and its content asynchronously.
This function will move a directory and all its content from source to dest. It will try first to rename the directory, if not it will try to use splice if possible, if not it will fallback to mmap/write. It will try to preserve access rights, but not user/group identity. Every file will be passed to the filter_cb, so it's your job to decide if you want to pass the file to the main_cb or not. Return ''true'' to pass it to the main_cb or ''false'' to ignore it.
The ''progress_cb'' receives the same arguments as its ''efl.Eio.moveFile()'' counterpart.
The ''filter_cb'' is called for each member of the directory and receives as argument the Eio File operation handle and the directory entry information, the latter as an object with the following keys:
* ''type'' - The type of the entry (file, etc).
* ''path'' - The path for the entry.
<note important>
If a rename occurs, the filter callback will not be called.
var operation = efl.Eio.moveFile(source, dest, progress_cb, done_cb, error_cb);
</code>
Parameters
* path - Should be the name of the file to move the data from.
* dest - Should be the name of the file to move the data to.
* progress_cb - Callback called to know the progress of the move.
* done_cb - Callback called when the operation is completed.
* error_cb - Callback called from if something goes wrong.
Return value
* object - A reference to the I/O operation as an Eio File object.
This function will move a file from source to dest. It will try to use splice if possible, if not it will fallback to mmap/write. It will try to preserve access rights, but not user/group identification.
The ''info'' argument to ''progress_cb'' is an object with the following keys:
* ''op'' - The operation being worked on.
* ''current'' - Current step in the I/O operation.
var operation = efl.Eio.openFile(path, open_cb, error_cb);
</code>
Parameters
* path - The path to be open.
* shared - If it's a shared memory file.
* open_cb - Callback called when the operation is completed.
* error_cb - Callback called from if something goes wrong.
Return value
* object - A reference to the I/O operation as an Eio File object.
Asynchronously open a file. The ''open_cb'' callback is called when the file is open and will receive the operation handle and the file handle respectively, the latter being an Eina File.
var operation = efl.Eio.unlinkDir(path, dest, filter_cb, progress_cb, done_cb, error_cb);
</code>
Parameters
* path - Should be the name of the directory to destroy.
* filter_cb - Possible to deny the destruction of some files/directories.
* progress_cb - Callback called to know the progress of the move.
* done_cb - Callback called when the operation is completed.
* error_cb - Callback called from if something goes wrong.
Return value
* object - A reference to the I/O operation as an Eio File object.
This function will remove a directory and all its content. Every file will be passed to the filter_cb, so it's your job to decide if you want to pass the file to the main_cb or not. Return ''true'' to pass it to the main_cb or ''false'' to ignore it.
The ''progress_cb'' receives the same arguments as its ''efl.Eio.moveFile()'' counterpart.
The ''filter_cb'' is called for each member of the directory and receives as argument the Eio File operation handle and the directory entry information, the latter as an object with the following keys:
These functions provide syntatic sugar to create event handlers for monitored items. Each function creates a handler watching the respective monitor event, i.e. ''addEventMonitorFileClosedHandler'' will watch for ''efl.EIO.MONITOR_FILE_CLOSED'' events. They are related to ''efl.Ecore.Event.addHandler()''.
Syntax
<code javascript>
function callback(eventType) {...};
var handler = efl.Eio.addEventMonitor...Handler();
</code>
Parameters
* callback - The callback to be called when the event occurs.