public interface FileSystem
An asynchronous and a synchronous version of each operation is provided.
The asynchronous versions take an AsynchronousResultHandler
which is
called when the operation completes or an error occurs.
The synchronous versions return the results, or throw exceptions directly.
It is highly recommended the asynchronous versions are used unless you are sure the operation will not block for a significant period of time
Modifier and Type | Method and Description |
---|---|
void |
chmod(java.lang.String path,
java.lang.String perms,
AsyncResultHandler<java.lang.Void> handler)
Change the permissions on the file represented by
path to perms , asynchronously. |
void |
chmod(java.lang.String path,
java.lang.String perms,
java.lang.String dirPerms,
AsyncResultHandler<java.lang.Void> handler)
Change the permissions on the file represented by
path to perms , asynchronously. |
void |
chmodSync(java.lang.String path,
java.lang.String perms)
Synchronous version of
chmod(String, String, AsyncResultHandler) |
void |
chmodSync(java.lang.String path,
java.lang.String perms,
java.lang.String dirPerms)
Synchronous version of
chmod(String, String, String, AsyncResultHandler) |
void |
copy(java.lang.String from,
java.lang.String to,
AsyncResultHandler<java.lang.Void> handler)
Copy a file from the path
from to path to , asynchronously. |
void |
copy(java.lang.String from,
java.lang.String to,
boolean recursive,
AsyncResultHandler<java.lang.Void> handler)
Copy a file from the path
from to path to , asynchronously. |
void |
copySync(java.lang.String from,
java.lang.String to)
Synchronous version of
copy(String, String, AsyncResultHandler) |
void |
copySync(java.lang.String from,
java.lang.String to,
boolean recursive)
Synchronous version of
copy(String, String, boolean, AsyncResultHandler) |
void |
createFile(java.lang.String path,
AsyncResultHandler<java.lang.Void> handler)
Creates an empty file with the specified
path , asynchronously. |
void |
createFile(java.lang.String path,
java.lang.String perms,
AsyncResultHandler<java.lang.Void> handler)
Creates an empty file with the specified
path and permissions perms , asynchronously. |
void |
createFileSync(java.lang.String path)
Synchronous version of
createFile(String, AsyncResultHandler) |
void |
createFileSync(java.lang.String path,
java.lang.String perms)
Synchronous version of
createFile(String, String, AsyncResultHandler) |
void |
delete(java.lang.String path,
AsyncResultHandler<java.lang.Void> handler)
Deletes the file represented by the specified
path , asynchronously. |
void |
delete(java.lang.String path,
boolean recursive,
AsyncResultHandler<java.lang.Void> handler)
Deletes the file represented by the specified
path , asynchronously. |
void |
deleteSync(java.lang.String path)
Synchronous version of
delete(String, AsyncResultHandler) |
void |
deleteSync(java.lang.String path,
boolean recursive)
Synchronous version of
delete(String, boolean, AsyncResultHandler) |
void |
exists(java.lang.String path,
AsyncResultHandler<java.lang.Boolean> handler)
Determines whether the file as specified by the path
path exists, asynchronously. |
boolean |
existsSync(java.lang.String path)
Synchronous version of
exists(String, AsyncResultHandler) |
void |
fsProps(java.lang.String path,
AsyncResultHandler<FileSystemProps> handler)
Returns properties of the file-system being used by the specified
path , asynchronously. |
FileSystemProps |
fsPropsSync(java.lang.String path)
Synchronous version of
fsProps(String, AsyncResultHandler) |
void |
link(java.lang.String link,
java.lang.String existing,
AsyncResultHandler<java.lang.Void> handler)
Create a hard link on the file system from
link to existing , asynchronously. |
void |
linkSync(java.lang.String link,
java.lang.String existing)
Synchronous version of
link(String, String, AsyncResultHandler) |
void |
lprops(java.lang.String path,
AsyncResultHandler<FileProps> handler)
Obtain properties for the link represented by
path , asynchronously. |
FileProps |
lpropsSync(java.lang.String path)
Synchronous version of
lprops(String, AsyncResultHandler) |
void |
mkdir(java.lang.String path,
AsyncResultHandler<java.lang.Void> handler)
Create the directory represented by
path , asynchronously. |
void |
mkdir(java.lang.String path,
boolean createParents,
AsyncResultHandler<java.lang.Void> handler)
Create the directory represented by
path , asynchronously. |
void |
mkdir(java.lang.String path,
java.lang.String perms,
AsyncResultHandler<java.lang.Void> handler)
Create the directory represented by
path , asynchronously. |
void |
mkdir(java.lang.String path,
java.lang.String perms,
boolean createParents,
AsyncResultHandler<java.lang.Void> handler)
Create the directory represented by
path , asynchronously. |
void |
mkdirSync(java.lang.String path)
Synchronous version of
mkdir(String, AsyncResultHandler) |
void |
mkdirSync(java.lang.String path,
boolean createParents)
Synchronous version of
mkdir(String, boolean, AsyncResultHandler) |
void |
mkdirSync(java.lang.String path,
java.lang.String perms)
Synchronous version of
mkdir(String, String, AsyncResultHandler) |
void |
mkdirSync(java.lang.String path,
java.lang.String perms,
boolean createParents)
Synchronous version of
mkdir(String, String, boolean, AsyncResultHandler) |
void |
move(java.lang.String from,
java.lang.String to,
AsyncResultHandler<java.lang.Void> handler)
Move a file from the path
from to path to , asynchronously. |
void |
moveSync(java.lang.String from,
java.lang.String to)
Synchronous version of
move(String, String, AsyncResultHandler) |
void |
open(java.lang.String path,
AsyncResultHandler<AsyncFile> handler)
Open the file represented by
path , asynchronously. |
void |
open(java.lang.String path,
java.lang.String perms,
AsyncResultHandler<AsyncFile> handler)
Open the file represented by
path , asynchronously. |
void |
open(java.lang.String path,
java.lang.String perms,
boolean createNew,
AsyncResultHandler<AsyncFile> handler)
Open the file represented by
path , asynchronously. |
void |
open(java.lang.String path,
java.lang.String perms,
boolean read,
boolean write,
boolean createNew,
AsyncResultHandler<AsyncFile> handler)
Open the file represented by
path , asynchronously. |
void |
open(java.lang.String path,
java.lang.String perms,
boolean read,
boolean write,
boolean createNew,
boolean flush,
AsyncResultHandler<AsyncFile> handler)
Open the file represented by
path , asynchronously. |
AsyncFile |
openSync(java.lang.String path)
Synchronous version of
open(String, AsyncResultHandler) |
AsyncFile |
openSync(java.lang.String path,
java.lang.String perms)
Synchronous version of
open(String, String, AsyncResultHandler) |
AsyncFile |
openSync(java.lang.String path,
java.lang.String perms,
boolean createNew)
Synchronous version of
open(String, String, boolean, AsyncResultHandler) |
AsyncFile |
openSync(java.lang.String path,
java.lang.String perms,
boolean read,
boolean write,
boolean createNew)
Synchronous version of
open(String, String, boolean, boolean, boolean, AsyncResultHandler) |
AsyncFile |
openSync(java.lang.String path,
java.lang.String perms,
boolean read,
boolean write,
boolean createNew,
boolean flush)
Synchronous version of
open(String, String, boolean, boolean, boolean, boolean, AsyncResultHandler) |
void |
props(java.lang.String path,
AsyncResultHandler<FileProps> handler)
Obtain properties for the file represented by
path , asynchronously. |
FileProps |
propsSync(java.lang.String path)
Synchronous version of
props(String, AsyncResultHandler) |
void |
readDir(java.lang.String path,
AsyncResultHandler<java.lang.String[]> handler)
Read the contents of the directory specified by
path , asynchronously. |
void |
readDir(java.lang.String path,
java.lang.String filter,
AsyncResultHandler<java.lang.String[]> handler)
Read the contents of the directory specified by
path , asynchronously. |
java.lang.String[] |
readDirSync(java.lang.String path)
Synchronous version of
readDir(String, AsyncResultHandler) |
java.lang.String[] |
readDirSync(java.lang.String path,
java.lang.String filter)
Synchronous version of
readDir(String, String, AsyncResultHandler) |
void |
readFile(java.lang.String path,
AsyncResultHandler<Buffer> handler)
Reads the entire file as represented by the path
path as a Buffer , asynchronously. |
Buffer |
readFileSync(java.lang.String path)
Synchronous version of
readFile(String, AsyncResultHandler) |
void |
readSymlink(java.lang.String link,
AsyncResultHandler<java.lang.String> handler)
Returns the path representing the file that the symbolic link specified by
link points to, asynchronously. |
java.lang.String |
readSymlinkSync(java.lang.String link)
Synchronous version of
readSymlink(String, AsyncResultHandler) |
void |
symlink(java.lang.String link,
java.lang.String existing,
AsyncResultHandler<java.lang.Void> handler)
Create a symbolic link on the file system from
link to existing , asynchronously. |
void |
symlinkSync(java.lang.String link,
java.lang.String existing)
Synchronous version of
link(String, String, AsyncResultHandler) |
void |
truncate(java.lang.String path,
long len,
AsyncResultHandler<java.lang.Void> handler)
Truncate the file represented by
path to length len in bytes, asynchronously. |
void |
truncateSync(java.lang.String path,
long len)
Synchronous version of
truncate(String, long, AsyncResultHandler) |
void |
unlink(java.lang.String link,
AsyncResultHandler<java.lang.Void> handler)
Unlinks the link on the file system represented by the path
link , asynchronously. |
void |
unlinkSync(java.lang.String link)
Synchronous version of
unlink(String, AsyncResultHandler) |
void |
writeFile(java.lang.String path,
Buffer data,
AsyncResultHandler<java.lang.Void> handler)
Creates the file, and writes the specified
Buffer data to the file represented by the path path ,
asynchronously. |
void |
writeFileSync(java.lang.String path,
Buffer data)
Synchronous version of
writeFile(String, Buffer, AsyncResultHandler) |
void copy(java.lang.String from, java.lang.String to, AsyncResultHandler<java.lang.Void> handler)
from
to path to
, asynchronously.The copy will fail if the destination already exists.
void copySync(java.lang.String from, java.lang.String to) throws java.lang.Exception
copy(String, String, AsyncResultHandler)
java.lang.Exception
void copy(java.lang.String from, java.lang.String to, boolean recursive, AsyncResultHandler<java.lang.Void> handler)
from
to path to
, asynchronously.
If recursive
is true
and from
represents a directory, then the directory and its contents
will be copied recursively to the destination to
.
The copy will fail if the destination if the destination already exists.
void copySync(java.lang.String from, java.lang.String to, boolean recursive) throws java.lang.Exception
copy(String, String, boolean, AsyncResultHandler)
java.lang.Exception
void move(java.lang.String from, java.lang.String to, AsyncResultHandler<java.lang.Void> handler)
from
to path to
, asynchronously.The move will fail if the destination already exists.
void moveSync(java.lang.String from, java.lang.String to) throws java.lang.Exception
move(String, String, AsyncResultHandler)
java.lang.Exception
void truncate(java.lang.String path, long len, AsyncResultHandler<java.lang.Void> handler)
path
to length len
in bytes, asynchronously.
The operation will fail if the file does not exist or len
is less than zero
.
void truncateSync(java.lang.String path, long len) throws java.lang.Exception
truncate(String, long, AsyncResultHandler)
java.lang.Exception
void chmod(java.lang.String path, java.lang.String perms, AsyncResultHandler<java.lang.Void> handler)
path
to perms
, asynchronously.
The permission String takes the form rwxr-x--- as
specified here.void chmodSync(java.lang.String path, java.lang.String perms) throws java.lang.Exception
chmod(String, String, AsyncResultHandler)
java.lang.Exception
void chmod(java.lang.String path, java.lang.String perms, java.lang.String dirPerms, AsyncResultHandler<java.lang.Void> handler)
path
to perms
, asynchronously.
The permission String takes the form rwxr-x--- as
specified in {here}.
If the file is directory then all contents will also have their permissions changed recursively. Any directory permissions will
be set to dirPerms
, whilst any normal file permissions will be set to perms
.
void chmodSync(java.lang.String path, java.lang.String perms, java.lang.String dirPerms) throws java.lang.Exception
chmod(String, String, String, AsyncResultHandler)
java.lang.Exception
void props(java.lang.String path, AsyncResultHandler<FileProps> handler)
path
, asynchronously.
If the file is a link, the link will be followed.FileProps propsSync(java.lang.String path) throws java.lang.Exception
props(String, AsyncResultHandler)
java.lang.Exception
void lprops(java.lang.String path, AsyncResultHandler<FileProps> handler)
path
, asynchronously.
The link will not be followed.FileProps lpropsSync(java.lang.String path) throws java.lang.Exception
lprops(String, AsyncResultHandler)
java.lang.Exception
void link(java.lang.String link, java.lang.String existing, AsyncResultHandler<java.lang.Void> handler)
link
to existing
, asynchronously.void linkSync(java.lang.String link, java.lang.String existing) throws java.lang.Exception
link(String, String, AsyncResultHandler)
java.lang.Exception
void symlink(java.lang.String link, java.lang.String existing, AsyncResultHandler<java.lang.Void> handler)
link
to existing
, asynchronously.void symlinkSync(java.lang.String link, java.lang.String existing) throws java.lang.Exception
link(String, String, AsyncResultHandler)
java.lang.Exception
void unlink(java.lang.String link, AsyncResultHandler<java.lang.Void> handler)
link
, asynchronously.void unlinkSync(java.lang.String link) throws java.lang.Exception
unlink(String, AsyncResultHandler)
java.lang.Exception
void readSymlink(java.lang.String link, AsyncResultHandler<java.lang.String> handler)
link
points to, asynchronously.java.lang.String readSymlinkSync(java.lang.String link) throws java.lang.Exception
readSymlink(String, AsyncResultHandler)
java.lang.Exception
void delete(java.lang.String path, AsyncResultHandler<java.lang.Void> handler)
path
, asynchronously.void deleteSync(java.lang.String path) throws java.lang.Exception
delete(String, AsyncResultHandler)
java.lang.Exception
void delete(java.lang.String path, boolean recursive, AsyncResultHandler<java.lang.Void> handler)
path
, asynchronously.
If the path represents a directory and recursive = true
then the directory and its contents will be
deleted recursively.
void deleteSync(java.lang.String path, boolean recursive) throws java.lang.Exception
delete(String, boolean, AsyncResultHandler)
java.lang.Exception
void mkdir(java.lang.String path, AsyncResultHandler<java.lang.Void> handler)
path
, asynchronously.The operation will fail if the directory already exists.
void mkdirSync(java.lang.String path) throws java.lang.Exception
mkdir(String, AsyncResultHandler)
java.lang.Exception
void mkdir(java.lang.String path, boolean createParents, AsyncResultHandler<java.lang.Void> handler)
path
, asynchronously.
If createParents
is set to true
then any non-existent parent directories of the directory
will also be created.
The operation will fail if the directory already exists.
void mkdirSync(java.lang.String path, boolean createParents) throws java.lang.Exception
mkdir(String, boolean, AsyncResultHandler)
java.lang.Exception
void mkdir(java.lang.String path, java.lang.String perms, AsyncResultHandler<java.lang.Void> handler)
path
, asynchronously.
The new directory will be created with permissions as specified by perms
.
The permission String takes the form rwxr-x--- as specified
in here.
The operation will fail if the directory already exists.
void mkdirSync(java.lang.String path, java.lang.String perms) throws java.lang.Exception
mkdir(String, String, AsyncResultHandler)
java.lang.Exception
void mkdir(java.lang.String path, java.lang.String perms, boolean createParents, AsyncResultHandler<java.lang.Void> handler)
path
, asynchronously.
The new directory will be created with permissions as specified by perms
.
The permission String takes the form rwxr-x--- as specified
in here.
If createParents
is set to true
then any non-existent parent directories of the directory
will also be created.
The operation will fail if the directory already exists.
void mkdirSync(java.lang.String path, java.lang.String perms, boolean createParents) throws java.lang.Exception
mkdir(String, String, boolean, AsyncResultHandler)
java.lang.Exception
void readDir(java.lang.String path, AsyncResultHandler<java.lang.String[]> handler)
path
, asynchronously.The result is an array of String representing the paths of the files inside the directory.
java.lang.String[] readDirSync(java.lang.String path) throws java.lang.Exception
readDir(String, AsyncResultHandler)
java.lang.Exception
void readDir(java.lang.String path, java.lang.String filter, AsyncResultHandler<java.lang.String[]> handler)
path
, asynchronously.
The paramater filter
is a regular expression. If filter
is specified then only the paths that
match @{filter}will be returned.
The result is an array of String representing the paths of the files inside the directory.
java.lang.String[] readDirSync(java.lang.String path, java.lang.String filter) throws java.lang.Exception
readDir(String, String, AsyncResultHandler)
java.lang.Exception
void readFile(java.lang.String path, AsyncResultHandler<Buffer> handler)
path
as a Buffer
, asynchronously.Do not user this method to read very large files or you risk running out of available RAM.
Buffer readFileSync(java.lang.String path) throws java.lang.Exception
readFile(String, AsyncResultHandler)
java.lang.Exception
void writeFile(java.lang.String path, Buffer data, AsyncResultHandler<java.lang.Void> handler)
Buffer data
to the file represented by the path path
,
asynchronously.void writeFileSync(java.lang.String path, Buffer data) throws java.lang.Exception
writeFile(String, Buffer, AsyncResultHandler)
java.lang.Exception
void open(java.lang.String path, AsyncResultHandler<AsyncFile> handler)
path
, asynchronously.The file is opened for both reading and writing. If the file does not already exist it will be created. Write operations will not automatically flush to storage.
AsyncFile openSync(java.lang.String path) throws java.lang.Exception
open(String, AsyncResultHandler)
java.lang.Exception
void open(java.lang.String path, java.lang.String perms, AsyncResultHandler<AsyncFile> handler)
path
, asynchronously.
The file is opened for both reading and writing. If the file does not already exist it will be created with the
permissions as specified by perms
.
Write operations will not automatically flush to storage.
AsyncFile openSync(java.lang.String path, java.lang.String perms) throws java.lang.Exception
open(String, String, AsyncResultHandler)
java.lang.Exception
void open(java.lang.String path, java.lang.String perms, boolean createNew, AsyncResultHandler<AsyncFile> handler)
path
, asynchronously.
The file is opened for both reading and writing. If the file does not already exist and
createNew
is true
it will be created with the permissions as specified by perms
, otherwise
the operation will fail.
Write operations will not automatically flush to storage.
AsyncFile openSync(java.lang.String path, java.lang.String perms, boolean createNew) throws java.lang.Exception
open(String, String, boolean, AsyncResultHandler)
java.lang.Exception
void open(java.lang.String path, java.lang.String perms, boolean read, boolean write, boolean createNew, AsyncResultHandler<AsyncFile> handler)
path
, asynchronously.
If read
is true
the file will be opened for reading. If write
is true
the file
will be opened for writing.
If the file does not already exist and
createNew
is true
it will be created with the permissions as specified by perms
, otherwise
the operation will fail.
Write operations will not automatically flush to storage.
AsyncFile openSync(java.lang.String path, java.lang.String perms, boolean read, boolean write, boolean createNew) throws java.lang.Exception
open(String, String, boolean, boolean, boolean, AsyncResultHandler)
java.lang.Exception
void open(java.lang.String path, java.lang.String perms, boolean read, boolean write, boolean createNew, boolean flush, AsyncResultHandler<AsyncFile> handler)
path
, asynchronously.
If read
is true
the file will be opened for reading. If write
is true
the file
will be opened for writing.
If the file does not already exist and
createNew
is true
it will be created with the permissions as specified by perms
, otherwise
the operation will fail.
If flush
is true
then all writes will be automatically flushed through OS buffers to the underlying
storage on each write.
AsyncFile openSync(java.lang.String path, java.lang.String perms, boolean read, boolean write, boolean createNew, boolean flush) throws java.lang.Exception
open(String, String, boolean, boolean, boolean, boolean, AsyncResultHandler)
java.lang.Exception
void createFile(java.lang.String path, AsyncResultHandler<java.lang.Void> handler)
path
, asynchronously.void createFileSync(java.lang.String path) throws java.lang.Exception
createFile(String, AsyncResultHandler)
java.lang.Exception
void createFile(java.lang.String path, java.lang.String perms, AsyncResultHandler<java.lang.Void> handler)
path
and permissions perms
, asynchronously.void createFileSync(java.lang.String path, java.lang.String perms) throws java.lang.Exception
createFile(String, String, AsyncResultHandler)
java.lang.Exception
void exists(java.lang.String path, AsyncResultHandler<java.lang.Boolean> handler)
path
exists, asynchronously.boolean existsSync(java.lang.String path) throws java.lang.Exception
exists(String, AsyncResultHandler)
java.lang.Exception
void fsProps(java.lang.String path, AsyncResultHandler<FileSystemProps> handler)
path
, asynchronously.FileSystemProps fsPropsSync(java.lang.String path) throws java.lang.Exception
fsProps(String, AsyncResultHandler)
java.lang.Exception