Posts

Showing posts from September, 2018

Adding a test in FilerJS for fs.promises.rename()

Image
FilerJS: adding a simple test and reviewing a pull request: FilerJS is an open source Javascript library that acts as an adapter to allow you to interact with a web browser's IndexedDB or WebSQL APIs to make them behave like a Unix style filesystem. Filer itself mimics the function definitions of the fs module of Node.js (which actually modifies files on a server). While the concept of creating an entire library that essentially one big adapter is fascinating in terms of applying design patterns to functional Javascript programming, I currently have little idea how any of this works. In this case, the best approach to become acquainted with the Filer project  was to look through the code and try to expand its unit tests. At the time of writing, I and y classmates were informed that Filer had recently had methods added to mimic Node's fs.promises tests, but no unit tests we added for these new functions. I started simple by creating an  issue to add a test to check that f

Node fs: Renaming Files

Image
Overview: Node.js features an handy filesystem module, called fs. The module provides synchronous, asynchronous, and new Promise functionality for many of its functions. This blog entry will focus on messing around with the file renaming functionality of the fs module through the module's various rename functions. fs Functions for Renaming Files The Node.js f module api can be found here . It includes 3 functions for renaming files. They all do more or less he same thing, but they differ in how those actions are run synchronously or asynchronously. The easiest functions to understand is the synchronous one, however it is also the most inefficient to use: fs.renameSync(oldPath, newPath) This functions just takes the location/path of the file to be renamed (which can be expresses as a string literal like "./renameMe.txt"), and the path for the new file [does attempting to move to a nonexistent folder fail?]. The issue with this approach is that renaming files