Focaccia is a storage abstraction layer which allows to manage with easy files into your local or cloud storages.
- Installing
- How to use
- Adapters
- Initialize
- Operations:
Execute npm install --save @focaccia/focaccia
to your main project.
- To use this tool you will need to initialize two objects, the adapter and the abstraction layer.
- Local file system (included in this package)
- AWS
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), {});
let res = tAsty.write("helloworld.txt", "Hello World"); // returns a promise
res.then((d) => {
console.log("RESULT", d);
})
let res = tAsty.has("helloworld.txt"); // returns a promise
res.then((data) => console.log(data));
Output
boolean: true or false if exists
let res = tAsty.read("helloworld.txt"); // returns a promise
res.then((data) => console.log(data));
Output
String: File content
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
let res = tAsty.rename("helloworld.txt", "mynewname.txt"); // returns a promise
res.then((data) => console.log(data));
Output
boolean: true or false if exists
let res = tAsty.copy("mynewname.txt", "helloworld.txt"); // returns a promise
res.then((data) => console.log(data));
Output
boolean: true or false if exists
let res = tAsty.delete("helloworld.txt"); // returns a promise
res.then((data) => console.log(data));
Output
boolean: true or false if exists
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
let res = tAsty.listContents("test"); // returns a promise
res.then((data) => console.log(data));
Output
[...array of files and folders]
let res = tAsty.deleteDir("test"); // returns a promise
res.then((data) => console.log(data));
Output
boolean: true or false if exists
It is possible to create, retrieve, delete and update buffers or streams by using the methods:
writeStream, readStream, putStream and delete.