fsso
v1.3.0
Published
An easier way to manage files.
Downloads
4
Maintainers
Readme
File System Simple Objects
A simplified, object oriented File System module.
Example
const fsso = require('fsso')
var dir = new fsso.Directory('./example')
console.log(dir.hierarchy())
var file = dir.find('example.txt') //or fsso.File('./example/example.txt')
console.log(file.read())
Installation
Installation is very easy with npm:
$ npm install fsso
Features
- An easier way to manage files in Node.JS
- Files are automatically changed in the object when they are changed on the computer
- Supports Read/Write streams
Properties
.path
returns the path of the directory or file
var dirPath = Directory.path
var filePath = File.path
typeof fileOrDirPath == "string"
.name
returns the name of the directory or file
var dirName = Directory.name
var fileName = File.name
typeof fileOrDirName == "string"
which is equivalent to
path.parse(fileOrDirPath).base
.relativePath
returns the directory or file path relative to the current running directory, require.main.filename
, or, when that doesn't work (such as in Command Prompt REPL instances), process.cwd()
var dirRelativePath = Directory.relativePath
var fileRelativePath = File.relativePath
typeof fileOrDirRelativePath == "string"
Directory Properties
.files
returns a list of all the files and folders in a directory
var dirFiles = Directory.files
typeof dirFiles == "string"
Methods
.hierarchy()
returns the structure of a file or directory
var dirHierarchy = Directory.hierarchy()
var fileHierarchy = File.hierarchy()
typeof dirOrFileHierarchy == "object"
example:
console.log(Directory.hierarchy())
//returns { name: "[dirName]", type: "dir", files: [array of hierarchies] }
console.log(File.hierarchy())
//returns { name: "[dirName]", type: "file" }
.isDirectory()
returns if an fsObject
is a directory
Directory.isDirectory() == true
File.isDirectory() == false
.isFile()
returns if an fsObject
is a file
Directory.isFile() == false
File.isFile() == true
.delete()
deletes an fsObject
and it's corresponding on-drive file or directory; returns undefined
WARNING: Deletes files and directories! Use with care.
Directory.delete()
File.delete()
Directory Methods
.mkDir( name, [mode] )
creates a sub-directory inside the directory and returns a Directory
object
var newDir = Directory.mkDir( name, mode )
newDir instanceof Directory
.create( name )
creates a file with the given name and returns it as a File
object
name
: <string>
var newFile = Directory.create( name )
newFile instanceof File
.remove( name )
removes a file or sub-directory from the directory and it's corresponding on-drive file or directory; returns undefined
name
: <string>
WARNING: Deletes files and directories! Use with care.
Directory.remove( name )
.find( name )
finds a given file or directory name in a directory and returns an fsObject
name
: <string>
var fileOrDir = Directory.find( name )
fileOrDir instanceof fsObject
File Methods
.read( [options] )
reads a file and returns a Buffer unless otherwise specified by options
var data = File.read( options )
data instanceof Buffer || typeof data =="string"
.write( data, [options] )
writes in a file
WARNING: Modifies files! Use with care.
var data = File.write( data, options )
data instanceof Buffer || typeof data =="string"
.createReadStream( [options] )
returns a readable stream
var readStream = File.createReadStream( options )
.createWriteStream( [options] )
returns a writeable stream
WARNING: Modifies files! Use with care.
var writeStream = File.createWriteStream( data, options )