1.3.0 • Published 6 years ago

fsso v1.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

File System Simple Objects

A simplified, object oriented File System module.

FS Objects npm version Downloads per Month Total Downloads License (MIT)

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

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

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

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 )
1.3.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago