filedump

Store files

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.

npm install filedump
var filedump = require("filedump")("/path/to/storage", 20);
 
/* file in the filesystem */
filedump.save("/some/file.ext", function(errfilename){
    if (err) return console.error(err);
    console.log(filename);
});
 
/* buffer */
filedump.save(new Buffer("data"), "txt", function(errfilename){
    if (err) return console.error(err);
    console.log(filename);
});
 
/* readble stream */
var rs = require("fs").createReadStream("/some/file.ext");
filedump.save(ts, "txt", function(errfilename){
    if (err) return console.error(err);
    console.log(filename);
});
  • path points to the folder where the files are stored
  • len 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 stream
  • ext is the file extention for the generated file. this is automatically determined when the first argument is a file path
  • callback has err and filename 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 stream
  • ext is the file extention for the generated file. this is automatically determined when the first argument is a file path
  • callback has err and filename 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 path
  • callback has err and filename as arguments

Delete a file and clear its parent directories.

  • file is the file name relative to the storage folder
  • callback has err as an argument

Public Domain