Pseudo File System Plugin
Plugin to add a pseudo file system to terminal-in-react
npm i -S terminal-in-react-pseudo-file-system-plugin
yarn add terminal-in-react-pseudo-file-system-plugin
The default export is a function the returns the plugin class. The function takes
on argument the
pathSeporator this is defaulted to
'\' so it is not required.
You can also specify the storage type for the filesystem. There are two types
basic is the default type and just uses client side json object and as such will not keep files from one session to another.
db uses indexedDb and as such only works in browsers where it is supported but has the benefit of keeping files from session to session.
If you use the
db storage type there is a third parameter that can be passed in
for if you would like to clear the db on start, by default it is
import pseudoFileSystemPlugin from 'terminal-in-react-pseudo-file-system-plugin';const FileSystemPlugin = ;...<Terminal=/>...
The commands it adds are:
Plugin public methods
The methods available to other plugins
The Path Object
Path objects are core to most of the functions. It has a few parts.
parts: an array of the string parts of the path that would be separated by the path separator
isDir: if this path points to a directory
isRoot: if the given path string when parsed was a full path or not
The way to create these objects is via the
parsePath method. This function will take a
string path and return a path object. This object is just a representation of a path
it does not mean that anything exist at that path.
Validating if a path exists
To check that a given path object points to something in the filesystem you need to
isValidPath method. This function take a path object and a callback as its
parameters. If the path is valid will be returned to the callback as a parameter.
Path back into a string
To take a path object and turn it back into a string just pass it into the method
To read a file's contents use the
readFile method. This function takes a path object and
a callback function. The callback will receive the string contents of the file or
if there was some issue reading the file.
To read a directory's contents use the
readDir method. This function takes a path object and a callback function. The callback will receive an array of objects refrencing the files and folders that are children of the folder or
null if there was an issue getting the contents.