writeFile
Description
Takes a file descriptor and writes content to a file. The file descriptor is resolved if the writting is succeeded. This function should be used in conjunction with openFile or openFileToWrite functions.
Parameter List | Returns | Rejection Errors |
---|---|---|
| Promise<string> | |
Related Functions | Function Signature | |
function writeFile(fileLocationAndName, content[, tuple]): Promise<string> |
Examples
1
2
3
4
5
import { writeFile, openFileToWrite } from "puddy-m/lib/fileFunctions";
openFileToWrite("aba.txt").then((fileDescriptor) =>
writeFile(fileDescriptor, "Content to Write")
);
1
2
3
4
5
6
import { writeFile, openFileToWrite } from "puddy-m/lib/fileFunctions";
import { validateString } from "puddy-m/lib/validators";
validateString("foo.txt", [])
.then((tuple) => openFileToWrite(tuple[0], tuple))
.then(([_, fileDescriptor]) => writeFile(fileDescriptor, _ + ": Content")); // Creates a file containing "foo.txt: Content"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { writeFile, openFileToWrite } from "puddy-m/lib/fileFunctions";
const run = async () => {
try {
// Open file and writes content to it.
const openedFileDescriptor = await openFileToWrite("foo.txt");
const writenFileDescriptor = await writeFile(
openedFileDescriptor,
"bar fizz buzz"
);
} catch (e) {
console.log(e);
}
};
run();