closeFile
Description
Takes a file descriptor (a integer) and closes the file associated with the descriptor. If closing was successful, it resolves the file descriptor.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<number || Array> | |
Related Functions | Function Signature | |
function closeFile(fileDescriptor[, tuple]): Promise<number || Array> |
Examples
1
2
3
import { openFileToWrite, closeFile } from "puddy-m/lib/fileFunctions";
openFileToWrite("aba.txt").then(closeFile).then(console.log); // Prints a number representing the file descriptor
1
2
3
4
5
6
7
import { openFileToWrite, closeFile } from "puddy-m/lib/fileFunctions";
import { validateString } from "puddy-m/lib/validators";
validateString("foo.txt", [])
.then((tuple) => openFileToWrite(tuple[0], tuple))
.then(([_, fileDescriptor]) => closeFile(fileDescriptor))
.then(console.log); // Prints a number representing the file descriptor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { openFileToWrite, closeFile } from "puddy-m/lib/fileFunctions";
const run = async () => {
try {
// Open file and closes it returning file descriptor.
const openedFileDescriptor = await openFileToWrite("foo.txt");
const closedFileDescriptor = await closeFile(openedFileDescriptor);
console.log(closedFileDescriptor);
} catch (e) {
console.log(e);
}
};
run();