fs-mock
v1.2.1
Published
[ABANDONED] Simple fs mock with posix and windows file system styles
Downloads
1,274
Maintainers
Readme
fs-mock
Simple fs mock with posix and windows file system styles.
Help
Unfortunately I don't have any more time to maintain this repository :-(
Don't you want to save me and this project by taking over it?
Installation
$ npm install fs-mock
Usage
This module does not change original fs module in any way.
If you want to pass this module into other module, you will have to use for example rewire package.
var FS = require('fs-mock');
var fs = new FS({
'var': {}, // empty directory
'var/www/index.php': '', // empty file in /var/www, so directory var is now not empty
'home/david/documents/school/projects': {},
'home': {
'david': {},
'john': {
'password.txt': 'my super password' // file
}
}
});
var myPassword = fs.readFileSync('/home/john/password.txt', {encoding: 'utf8'}); // my super password
If you write some path like this: home/david/documents/school/projects
, it will be automatically expanded and all its
parent directories will be also added to mocked file system.
Windows
var fs = new FS({
'Users': {
'David': {
'password.txt': 'my super password'
}
}
}, {
windows: true
});
This will change delimiter from /
to \
and add root directory to c:
.
Other drives
new FS({ ... }, {
windows: true,
drives: ['c:', 'd:', 'z:']
});
Another root directory
new FS({ ... }, {
windows: true,
drives: ['c:', 'd:', 'z:'],
root: 'z:'
});
Now every path will be saved into z:
drive.
If you want to save paths to custom drives, you need to disable auto saving into options.root
.
new FS({
'c:': {
'Users': {}
},
'x:': {
'xampp': {
'htdocs': {}
}
}
}, {
windows: true,
root: false
});
I haven't got any machine with Windows so all methods (like chmod) works just like in Unix systems. Please let me know if you want to improve this and how.
Supported functions
There are also all *Sync methods.
Calling unsupported methods will throw an exception.
Fs object:
fs.rename()
: yesfs.ftruncate()
: yesfs.truncate()
: yesfs.chown()
: yesfs.fchown()
: yesfs.lchown()
: yesfs.chmod()
: yesfs.fchmod()
: yesfs.lchmod()
: yesfs.stat()
: yesfs.lstat()
: yesfs.fstat()
: yesfs.link()
: yesfs.symlink()
: yes (type argument is ignored)fs.readlink()
: yesfs.realpath()
: yesfs.unlink()
: yesfs.rmdir()
: yesfs.mkdir()
: yesfs.readdir()
: yesfs.close()
: yesfs.open()
: yesfs.utimes()
: yesfs.futimes()
: yesfs.write()
: yesfs.read()
: yesfs.readFile()
: yesfs.writeFile()
: yesfs.appendFile()
: yesfs.watchFile()
: no (use fs.watch())fs.unwatchFile()
: no (use fs.watch())fs.watch()
: yes (persistent option is ignored)fs.exists()
: yesfs.createReadStream()
: yesfs.createWriteStream()
: yes
Stats object:
dev
: noino
: nomode
: yesnlink
: nouid
: yesgid
: yesrdev
: nosize
: yesblksize
: yesblocks
: yesatime
: yesmtime
: yesctime
: yesisFile()
: yesisDirectory()
: yesisBlockDevice()
: noisCharacterDevice()
: noisSymbolicLink()
: yesisFIFO()
: noisSocket()
: no
Tests
$ npm test
Changelog
1.2.0 - 1.2.1
- Move repository under Carrooi organization
- Abandon project
- Rewritten to pure javascript
- Rebind all methods so they can be called event when they are unbound #11
- Updated dependencies
- Fixed root directories #15
- Added some tests
- Some fixes for Windows
- Fixed paths with trailing slashes #13
- Fixed lstat called on non symbolic links #14
- Allow writing raw buffer #7
1.1.3
- Bug with createReadStream and createWriteStream not emitting 'open' event #10
1.1.2
- Bug with createWriteStream sending improper 'finish' event
1.1.1
- Setup coffee-script for development
- createReadStream/createWriteStream send error events instead of exceptions
- createReadStream could not use custom
fd
in options
1.1.0
- Added support for windows file systems
- Added many tests
1.0.1
- Bug with root directories and readdir method
1.0.0
- First version