Search⌘ K

Exercise: A Virtual Filesystem

Explore how to implement a virtual filesystem in Node.js by modifying a filesystem adapter to store data in memory. Understand how to write and read files using caching techniques, manage asynchronous operations with promises, and handle errors effectively within a structural design pattern context.

Problem statement

Modify our LevelDB filesystem adapter example to write the file data in memory rather than in LevelDB. You can use an object or a Map instance to store the key-value pairs of filenames and the associated data.

Coding challenge

Write your solution code in the following code widget. We’ve already added the package.json file for your ease.

Node.js
{
"name": "Chapter-08",
"version": "1.0.0",
"description": "This examples shows how to use the adapter pattern to build an FS-like interface that writes to level db instead",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"level": "^6.0.0"
},
"engines": {
"node": ">=14"
},
"engineStrict": true
}

Solution

...