Awesome Open Source
Awesome Open Source

Focaccia

Build Status

Focaccia is a storage abstraction layer which allows to manage with easy files into your local or cloud storages.

Contents

Installing

Execute npm install --save @focaccia/focaccia to your main project.

How To Use:

  • To use this tool you will need to initialize two objects, the adapter and the abstraction layer.

Adapters:

  • Local file system (included in this package)
  • AWS

Initialize

const {Focaccia, LocalAdapter} = require("@focaccia/focaccia");

// This is the root directory to start uploading the files.
let rootDir = "/var/myproejct/data"; // Make sure this exists and has write access.
let tAsty = new Focaccia(new LocalAdapter(rootDir), {});

Writing a local file


let res = tAsty.write("helloworld.txt", "Hello World"); // returns a promise
res.then((d) => {
  console.log("RESULT", d);
})

Checking if a file exists

let res = tAsty.has("helloworld.txt"); // returns a promise
res.then((data) => console.log(data));

Output

boolean: true or false if exists

Reading a file

let res = tAsty.read("helloworld.txt"); // returns a promise
res.then((data) => console.log(data));

Output

String: File content

Reading a file and delete

This command is the same as above but with the difference that deletes the file after the read process.

let res = tAsty.readAndDelete("helloworld.txt"); // returns a promise
res.then((data) => console.log(data));

Output

String: File content

Rename

let res = tAsty.rename("helloworld.txt", "mynewname.txt"); // returns a promise
res.then((data) => console.log(data));

Output

boolean: true or false if exists

Copy

let res = tAsty.copy("mynewname.txt", "helloworld.txt"); // returns a promise
res.then((data) => console.log(data));

Output

boolean: true or false if exists

Delete

let res = tAsty.delete("helloworld.txt"); // returns a promise
res.then((data) => console.log(data));

Output

boolean: true or false if exists

Creates a directory

This will create a directory inside the root directory previously configured.

let res = tAsty.createDir("test"); // returns a promise
res.then((data) => console.log(data));

Output

boolean: true or false if exists

List directory content

let res = tAsty.listContents("test"); // returns a promise
res.then((data) => console.log(data));

Output

[...array of files and folders]

Delete a Directory

let res = tAsty.deleteDir("test"); // returns a promise
res.then((data) => console.log(data));

Output

boolean: true or false if exists

Buffer supports.

It is possible to create, retrieve, delete and update buffers or streams by using the methods:

writeStream, readStream, putStream and delete.


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Javascript (1,555,917
Nodejs (54,817
Node (13,120
Aws (11,183
Storage (1,691
Local (304
Abstraction (235
Layer (213
Related Projects