Store files, buffers or readble streams in the filesystem with an automatically generated random filename and divided in folders to circument file system limitations.
npm install filedump
var filedump = require("filedump")("/path/to/storage", 20);
/* file in the filesystem */
filedump.save("/some/file.ext", function(err, filename){
if (err) return console.error(err);
console.log(filename);
});
/* buffer */
filedump.save(new Buffer("data"), "txt", function(err, filename){
if (err) return console.error(err);
console.log(filename);
});
/* readble stream */
var rs = require("fs").createReadStream("/some/file.ext");
filedump.save(ts, "txt", function(err, filename){
if (err) return console.error(err);
console.log(filename);
});
path
points to the folder where the files are storedlen
is the length of the random generated string the directories and file name is derived from
Save data and call back with filename when file is written
data
can be a file path, buffer or readble streamext
is the file extention for the generated file. this is automatically determined when the first argument is a file pathcallback
haserr
andfilename
as arguments
Save data and call back with filename before file is written and without error reporting
data
can be a file path, buffer or readble streamext
is the file extention for the generated file. this is automatically determined when the first argument is a file pathcallback
haserr
andfilename
as arguments
Generate random file name, create directories and call back with file name
ext
is the file extention for the generated file. this is automatically determined when the first argument is a file pathcallback
haserr
andfilename
as arguments
Delete a file and clear its parent directories.
file
is the file name relative to the storage foldercallback
haserr
as an argument