1.0.8 • Published 7 years ago
@focaccia/focaccia v1.0.8
Focaccia
Focaccia is a storage abstraction layer which allows to manage with easy files into your local or cloud storages.
Contents
- Installing
- How to use
- Adapters
- Initialize
- Operations:
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 existsReading a file
let res = tAsty.read("helloworld.txt"); // returns a promise
res.then((data) => console.log(data));Output
String: File contentReading 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 contentRename
let res = tAsty.rename("helloworld.txt", "mynewname.txt"); // returns a promise
res.then((data) => console.log(data));Output
boolean: true or false if existsCopy
let res = tAsty.copy("mynewname.txt", "helloworld.txt"); // returns a promise
res.then((data) => console.log(data));Output
boolean: true or false if existsDelete
let res = tAsty.delete("helloworld.txt"); // returns a promise
res.then((data) => console.log(data));Output
boolean: true or false if existsCreates 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 existsList 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 existsBuffer supports.
It is possible to create, retrieve, delete and update buffers or streams by using the methods:
writeStream, readStream, putStream and delete.