vertx.filesystem documentation
Provides a broad set of functions for manipulating files. Wraps the
asynchronous methods from org.vertx.java.core.file.FileSystem.
*file-system*
var
The currently active default vertx container instance.
If not bound, the FileSystem from vertx.core/*vertx* will be used.
You should only need to bind this for advanced usage.
chmod
(chmod path perms handler)
(chmod path perms dir-perms handler)
Change the permissions on the file represented path to perms, asynchronously.
If dir-perms is provided and path is a directory, it will have its
permisions changed recursively, with perms being applied to any
files, and dir-perms being applied to directories. handler can
either be a single-arity fn that will be passed the exception (if
any) from the result of the call, or a Handler that will be called
with the AsyncResult object that wraps the exception.
The permission strings take the form rwxr-x--- as specified by
http://download.oracle.com/javase/7/docs/api/java/nio/file/attribute/PosixFilePermissions.html
close
(close file)
(close file handler)
Close the file, asynchronously.
handler can either be a single-arity fn that will be passed the
exception (if any) from the result of the call, or a Handler that
will be called with the AsyncResult object that wraps the
exception.
copy
(copy src dest handler)
(copy src dest recursive? handler)
Copy a file from the src path to dest path, asynchronously.
If recursive? is true and src represents a directory, then the
directory and its contents will be copied recursively to
dest. recursive? defaults to false. handler can either be a
single-arity fn that will be passed the exception (if any) from the
result of the copy call, or a Handler that will be called with the
AsyncResult object that wraps the exception.
The copy will fail if the destination already exists.
create-file
(create-file path handler)
(create-file path perms handler)
Creates an empty file with the specified path, asynchronously.
If perms are provided, they will override the default permissions
for the created file. The permission String takes the form
rwxr-x--- as specified by:
http://download.oracle.com/javase/7/docs/api/java/nio/file/attribute/PosixFilePermissions.html
handler can either be a single-arity fn that will be passed the
exception (if any) from the result of the call, or a Handler that
will be called with the AsyncResult object that wraps the
exception.
delete
(delete path handler)
(delete path recursive? handler)
Deletes the file on the file system represented by path, asynchronously.
handler can either be a single-arity fn that will be passed the
exception (if any) from the result of the call, or a Handler that
will be called with the AsyncResult object that wraps the
exception.
If the recursive? is true (default is false) and file is a
directory, it will be deleted recursively.
exists?
(exists? path handler)
Determines whether the file as specified by the path {@code path} exists, asynchronously.
handler can either be a two-arity fn that will be passed the
exception (if any) and the boolean result of the call, or a Handler
that will be called with the AsyncResult object that wraps the
exception and the boolean result.
file-system-properties
(file-system-properties path handler)
Returns properties of the file-system being used by the specified path, asynchronously.
handler can either be a two-arity fn that will be passed the
exception (if any) and properties (as a map) from the result of the
call, or a Handler that will be called with the AsyncResult object
that wraps the exception and FileSystemProps object.
flush
(flush file)
(flush file handler)
Flush any writes made to this file to underlying persistent storage, asynchronously.
handler can either be a single-arity fn that will be passed the
exception (if any) from the result of the call, or a Handler that
will be called with the AsyncResult object that wraps the
exception.
If the file was opened with :flush? true, then calling this method
will have no effect.
get-file-system
(get-file-system)
Returns the currently active FileSystem instance.
link
(link path existing handler)
(link path existing symbolic? handler)
Creates a link on the file system from path to existing, asynchronously.
If symbolic? is true (the default), the resulting link is symbolic,
otherwise a had link is created. handler can either be a
single-arity fn that will be passed the exception (if any) from the
result of the call, or a Handler that will be called with the
AsyncResult object that wraps the exception.
mkdir
(mkdir path handler)
(mkdir path create-parents? handler)
(mkdir path create-parents? perms handler)
Create the directory represented by path, asynchronously.
If create-parents? is true (default is false), any non-existent
parent directories of the directory will also be created. If perms
are provided, they will override the default permissions for the
created directory. The permission String takes the form rwxr-x---
as specified by:
http://download.oracle.com/javase/7/docs/api/java/nio/file/attribute/PosixFilePermissions.html
handler can either be a single-arity fn that will be passed the
exception (if any) from the result of the call, or a Handler that
will be called with the AsyncResult object that wraps the
exception.
The operation will fail if the directory already exists.
move
(move src dest handler)
Move a file from the src path to dest path, asynchronously.
handler can either be a single-arity fn that will be passed the
exception (if any) from the result of the move call, or a Handler
that will be called with the AsyncResult object that wraps the
exception.
The move will fail if the destination already exists.
open
(open path handler & {:keys [perms read? write? create? flush?], :or {read? true, write? true, create? true}})
Open the file represented by path, asynchronously.
handler can either be a two-arity fn that will be passed the
exception (if any) and the AsyncFile instance from the result of
the call, or a Handler that will be called with the AsyncResult
object that wraps the exception and the buffer.
The behavior of the open call is further controlled by a set of
kwarg arguments [default]:
* :create? - create the file if it does not already exist [true]
* :read? - open the file for reading [true]
* :write? - open the file for writing [true]
* :flush? - the opened file will auto-flush writes [false]
* :perms - the permissions used to create the file, if necessary
(see create-file) [nil]
properties
(properties path handler)
(properties path follow-link? handler)
Obtain properties for the file represented by path, asynchronously.
handler can either be a two-arity fn that will be passed the
exception (if any) and properties (as a map) from the result of the
call, or a Handler that will be called with the AsyncResult object
that wraps the exception and FileProps object.
The properties map passed to the handler fn will
contain :creation-time, :last-access-time, :last-modified-time,
:directory?, :regular-file?, :symbolic-link?, :other?, and :size.
If the follow-link? is true (the default) and file is a link, the
link will be followed.
read
(read file pos length handler)
(read file buffer! offset pos length handler)
Reads length bytes of data from the file at position pos in the file, asynchronously.
If provided, the read data will be written into buffer! at offset.
handler can either be a two-arity fn that will be passed the
exception (if any) and the Buffer from the result of the
call, or a Handler that will be called with the AsyncResult object
that wraps the exception and Buffer object.
If data is read past the end of the file then zero bytes will be
read. When multiple reads are invoked on the same file there are no
guarantees as to order in which those reads actually occur.
read-dir
(read-dir path handler)
(read-dir path filter handler)
Read the contents of the directory specified by path, asynchronously.
If a filter regex is specified then only the paths that match it
will be returned. handler can either be a two-arity fn that will be
passed the exception (if any) and a vector of String paths from the
result of the call, or a Handler that will be called with the
AsyncResult object that wraps the exception and a String[] of
paths.
read-file
(read-file path handler)
Reads the entire file as represented by the path path as a Buffer, asynchronously.
handler can either be a two-arity fn that will be passed the
exception (if any) and the Buffer from the result of the call, or a
Handler that will be called with the AsyncResult object that wraps
the exception and the buffer.
Do not user this method to read very large files or you
risk running out of available RAM.
resolve-symlink
(resolve-symlink path handler)
Returns the path representing the file that the symbolic link specified by path points to, asynchronously.
handler can either be a two-arity fn that will be passed the
exception (if any) and the String path from the result of the call,
or a Handler that will be called with the AsyncResult object that
wraps the exception and the String path.
truncate
(truncate path len handler)
Truncate the file represented by path to length len in bytes, asynchronously.
handler can either be a single-arity fn that will be passed the
exception (if any) from the result of the truncate call, or a
Handler that will be called with the AsyncResult object that wraps
the exception.
The truncate will fail if the file does not exist or len is less
than zero.
write
(write file data pos handler)
Write data to the file at position pos in the file, asynchronously.
data can anything bufferable (see vertx.buffer). If pos
lies outside of the current size of the file, the file will be
enlarged to encompass it. handler can either be a single-arity fn
that will be passed the exception (if any) from the result of the
call, or a Handler that will be called with the AsyncResult object
that wraps the exception.
When multiple writes are invoked on the same file there are no
guarantees as to order in which those writes actually occur.
write-file
(write-file path data handler)
Creates the file, and writes the specified data to the file represented by path, asynchronously.
data can anything bufferable (see vertx.buffer). handler
can either be a single-arity fn that will be passed the
exception (if any) from the result of the call, or a Handler that
will be called with the AsyncResult object that wraps the
exception.