Introduction
Tomb is a groovy
library to use various filesystems in a quick an easy way. Tomb provides you with a generic abstraction based on the use of the java.nio.file.Path
class to manipulate files in a filesystem and several backends to use it against.
Right now, Tomb implements two backends, LocalFilesystem
and AmazonS3Filesystem
.
Usage
Each backend implement a list of methods described in the next section. To obtain a new backend for a Filesystem, we use the static method getFilesystem
:
// Local Filesystem
def fs = Tomb.getFilesystem('local', basePath: '/tmp')
fs.list()
// => lists all files on '/tmp'
// Amazon Filesystem
def fs = Tomb.getFilesystem('S3',
key: 'key',
secret: 'secret',
bucket: 'bucket',
basePath: '')
def myfile = new File('/tmp/wallpaper.png')
fs.put(myfile.newInputStream(), Paths.get('wallpaper.png'))
// => uploads the file to 'images/wallpaper.png'
Supported Filesystems
The different filesystems that Tomb
supports from scratch are:
Name | Filesystem parameter | Configuration Map |
---|---|---|
Local |
|
|
AmazonS3 |
|
|
FilesystemProvider interface
FilesystemProvider
is the interface that all the backends implement. It has the following methods:
Name | Returns | Parameters | Description |
---|---|---|---|
resolve |
Path relativePath |
Resolves a relative path against the filesystem base path |
|
exists |
Path relativePath |
Returns a Boolean value depending on the existence of the file in the filesystem |
|
get |
Path relativePath |
Returns an InputStream with the contents of the file |
|
lastModified |
Path relativePath |
Returns the last Date on which the file was modified |
|
put |
void |
InputStream inputStream Path relativePath |
Creates a file in the backend with the contents of the |
list |
Path relativePath |
Lists the contents of the backend’s path |
|
copy |
void |
Copies the |
|
move |
void |
Moves the |
|
delete |
void |
Path relativePath |
Deletes the file on the |
getUri |
Path relativePath |
Obtains the URI of the resource located on |