afimali v0.0.3
afimali
Another file manupulate library for nodeJS.
Please feel free to raise pull requests on github.
Install
npm install afimaliBasic Usage
const lib=require("afimali");
async function start()
{
let file=await lib.open("./test.bin"); //Open a file to edit.
let win=await file.openWindow(0, [5, 5]); //Open a 5x5 matrix as a window.
console.log(await win.at(0, 0)); //Read data from the window at 0,0.
await win.at(0, 0, 97); //Write 97 to window at 0,0.
await file.save(); //Save the file to storage.
}
start();Classes & Methods
afimali.open(path)
returns an instance of
Filewhich should opened the file on the path.- path
String, path to the file
- path
Class
FileThis is what you really need to manipulate your file.
Properties
- closed
BooleanTrue if the file is already closed. - openedWindows
Array<Window>The opened windows on the file.
- closed
Methods
stat() :
Promise<Stat>returns the file stat info.
openWindow(offset, winSize) :
Promise<Window>return a new window or an opened window from
openedWindows.- offset
Numberthe offset on the file. - winSize
Array<Number>an 1x2 array to indicate the size of the window.
- offset
undo() :
PromiseUndo a writing operation.save():
PromiseSave the file, this will clear the operation history. Means that after you call this method, you're no long able to use undo method before you do another write operating.
close() :
PromiseClose the file, close property will be set as
true, please do not call any another method on this object after calling this.
Class
WindowA class the you use to modify the content of a file.
- Properties
- buffer
Bufferthe content buffer. - size
Array<Number>the size of the window. - offset
Numberoffset on file. - length
Numberlength of buffer. - file
FileThe file which this window opened on.
- buffer
Methods
clone() :
Promise<Window>returns a cloned window of this.
at(x, y, data) :
Promise<Number>if
datais not passed, this method only returns the value on the position, if passed, the value on the cell will be replaced bydata.- x
Numberx position of cell. - y
Numbery position of cell. - data
Numberdata which will be set into the cell.
- x
disassemble(...slices) :
Promise<Buffer>returns a buffer whichi contains slices' data.
- slice
Array<Number>x, y, length
- slice
close() :
Promiseclose window
- Properties
Additional Files
Afimali supports reading structure from below file formats:
- GIF
- PNG
The files above are derived from File. Use openWindow to manipulate them.
Example
const lib=require("afimali");
async function start()
{
let file=await lib.open("./test.gif", lib.manipulators.GifFile);
console.log(file);
}
start();Documents
Please visit wiki page at https://github.com/malpower/afimali/wiki for docs.