0.0.6 • Published 11 years ago
filedump v0.0.6
filedump
Store files, buffers or readble streams in the filesystem with an automatically generated random filename and divided in folders to circument file system limitations.
Install
npm install filedumpUsage
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);
});API
filedump(path, len)
pathpoints to the folder where the files are storedlenis the length of the random generated string the directories and file name is derived from
filedump.save(data, ext, callback)
Save data and call back with filename when file is written
datacan be a file path, buffer or readble streamextis the file extention for the generated file. this is automatically determined when the first argument is a file pathcallbackhaserrandfilenameas arguments
filedump.dump(data, ext, callback)
Save data and call back with filename before file is written and without error reporting
datacan be a file path, buffer or readble streamextis the file extention for the generated file. this is automatically determined when the first argument is a file pathcallbackhaserrandfilenameas arguments
filedump.prepare(ext, callback)
Generate random file name, create directories and call back with file name
extis the file extention for the generated file. this is automatically determined when the first argument is a file pathcallbackhaserrandfilenameas arguments
filedump.delete(file, callback)
Delete a file and clear its parent directories.
fileis the file name relative to the storage foldercallbackhaserras an argument