diff --git a/specs/mini-vc/mini-vc.md b/specs/mini-vc/mini-vc.md index dd39ede6aba86db8d5ccff7bb04ba4dcf69fefd6..750f262b9e3f9b6d4abb5fcb6a33b33c78fee0fc 100644 --- a/specs/mini-vc/mini-vc.md +++ b/specs/mini-vc/mini-vc.md @@ -264,6 +264,19 @@ Note that these functions expect diffs in the form of `FileDiffs` objects, which You don't need to understand the code behind these functions, but I think the diffing algorithm is really cool, so please ask me if you want to know more! +## Filesystem functions + +Node.js provides an extensive set of functions for filesystem operations (reading and writing files, adding and removing directories, etc.). +The full set of functions can be found in the [documentation for the `fs` module](https://nodejs.org/api/fs.html). +All the functions have versions (in `require('fs').promises`, referred to by the documentation as `fsPromises`) that return `Promise`s, which are convenient to use with `async`-`await`. +The callback versions of the functions have better examples of what arguments you can pass, so I recommend reading their documentation. + +Here are the filesystem operations I used, but you are welcome to use others: +- [`fsPromises.access()`](https://nodejs.org/api/fs.html#fs_fspromises_access_path_mode): checks whether a file exists (the `Promise` will reject if it doesn't) +- [`fsPromises.mkdir()`](https://nodejs.org/api/fs.html#fs_fspromises_mkdir_path_options): makes a new (empty) directory +- [`fsPromises.readFile()`](https://nodejs.org/api/fs.html#fs_fspromises_readfile_path_options): reads the entire contents of a file as bytes or as a string (if you use encoding `'utf8'`) +- [`fsPromises.writeFile()`](https://nodejs.org/api/fs.html#fs_fspromises_writefile_file_data_options): sets the contents of a file, creating the file if it doesn't exist + ## Going further If you are interested and want to add more to the VC project, try adding support for "branches".