Wrapper around node fs module that encrypts the files on the fly
npm install crypto-fs --save
Node.js 4+
var fs = require('crypto-fs');
fs.init({
baseFs: require('fs'),
algorithm: 'aes-256-ctr',
prefix: '',
password: '1234',
root: './test/dest',
iv: null,
realSize: false,
dontEncPath : false
});
require("fs")
)
"aes-256-ctr"
)
""
)
null
)
false
)
false
)
By default, this module relies on the native fs module, but this can be changed. If you have a different module that exposes the same methods (e.g. ftp-fs, s3-fs), you can set it as the base fs.
For every exposed method, it will be documented which methods does it require from the base fs (except for the same method, readlink
/readlinkSync
and lstat
/lstatSync
). readlink
/readlinkSync
and lstat
/lstatSync
are used to determine if the given path is a symlink, and in this case follow the symlink.
If you're using the default fs module, you can ignore this info.
init
(non-standard)
existsSync
readFile
, readFileSync
writeFile
, writeFileSync
exists
, existsSync
access
, accessSync
mkdir
, mkdirSync
rmdir
, rmdirSync
unlink
, unlinkSync
stat
, statSync
readdir
,readdirSync
readlink
, readlinkSync
symlink
, symlinkSync
lstat
, lstatSync
rename
fs.readFile
, fs.writeFile
, fs.unlink
renameSync
fs.readFileSync
, fs.writeFileSync
, fs.unlinkSync
appendFile
access
(or exists
), readFile
, writeFile
appendFileSync
accessSync
(or existsSync
), readFileSync
, writeFileSync
createReadStream
createWriteStream
watchFile
unwatchFile
watch
close
, closeSync
fstat
, fstatSync
futimes
, futimesSync
fchown
, fchownSync
fchmod
, fchmodSync
utimes
, utimesSync
chown
, chownSync
chmod
, chmodSync
lchown
, lchownSync
lchmod
, lchmodSync
watch
filename will be incorect if it's not in the root
folder - should be possible to fixrename
and renameSync
create a new file and remove the old so the watch
might not behave as expected (would it be better to actually rename the file and write the new content?)link
and linkSync
can't work because the filename would be wrong and therefore the file content couldn't be decrypted. Not yet sure if it's possible to solve this.root
pathftruncate
truncate
realpath
fsync
link
open
write
read