openFile
Description
It takes the file location and opens it in the memory. It takes a flag to indicate whether the opening is for read or write. Resolves the fileDescriptor if successfully opened.
This function is a helper of more complex functions from this lib, eg: createFile or updateFile
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<number || Array> | |
Related Functions | Function Signature | |
function openFile(fileLocationAndName[, flag = 'r', tuple]): Promise<number || Array> |
Examples
1
2
3
4
import { openFile } from "puddy-m/lib/fileFunctions";
// if the file ./foo.txt exists, this function will resolve
openFile("./foo.txt").then((fileDescriptor) => console.log(fileDescriptor)); // prints an integer number
1
2
3
4
import { openFile } from "puddy-m/lib/fileFunctions";
// if the file ./foo.txt exists, this function will resolve
openFile("./foo.txt", "r").then((fileDescriptor) => console.log(fileDescriptor)); // prints an integer number
1
2
3
4
5
6
import { openFile } from "puddy-m/lib/fileFunctions";
// If you want to open a file that doesn't exist, then it will only resolve if
// the 'wx' is passed in the flag parameter
openFile("./notExisting.txt", "wx").then((fileDescriptor) =>
console.log(fileDescriptor)
); // prints an integer number