@focaccia/focaccia

Abstraction for local and remote filesystems for nodejs

Usage no npm install needed!

<script type="module">
  import focacciaFocaccia from 'https://cdn.skypack.dev/@focaccia/focaccia';
</script>

README

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.