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

'local'

basePath: The base path for all the operations of the filesystem

AmazonS3

'S3'

key: The Amazon api key

secret: The Amazon api secret

bucket: The Amazon S3 bucket name

basePath: The base path for all the operations of the filesystem

FilesystemProvider interface

FilesystemProvider is the interface that all the backends implement. It has the following methods:

Name Returns Parameters Description

resolve

Path

Path relativePath

Resolves a relative path against the filesystem base path

exists

Boolean

Path relativePath

Returns a Boolean value depending on the existence of the file in the filesystem

get

InputStream

Path relativePath

Returns an InputStream with the contents of the file

lastModified

Date

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 inputStream parameter

list

List<String>

Path relativePath

Lists the contents of the backend’s path

copy

void

Path initialRelativePath Path destinationRelativePath

Copies the initialRelativePath file to the destinationRelativePath route

move

void

Path initialRelativePath Path destinationRelativePath

Moves the initialRelativePath file to the destinationRelativePath route

delete

void

Path relativePath

Deletes the file on the relativePath route

getUri

URI

Path relativePath

Obtains the URI of the resource located on relativePath