api/utils/countlyFs

Module to abstract storing files on hard drive or in a shared system between multiple countly instances, currently based on GridFS

Source:

Members

(static) fs

Source:

Direct FS methods

(static) gridfs

Source:

Direct GridFS methods

(static) type

Source:

Currently used file storage type

Methods

(static) deleteFile(category, dest, optionsopt, callback)

Source:

Delete file from shared system

Example
countlyFs.deleteFile("test", "AGPLv3", function(err){
  console.log("Finished", err);
});
Parameters:
Name Type Attributes Description
category string

collection where to store data

dest string

file's destination

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

callback function

function called when deleting was completed or errored, providing error object as first param

(static) exists(category, dest, optionsopt, callback)

Source:

Check if file exists

Example
countlyFs.exists("test", "./CHANGELOG.md", function(err, exists){
  if(exists)
      console.log("File exists");
});
Parameters:
Name Type Attributes Description
category string

collection where to store data for gridfs

dest string

file's destination

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

callback function

function called when we have result, providing error object as first param and boolean as second to indicate if file exists

(static) getData(category, dest, optionsopt, callback)

Source:

Get file data

Example
countlyFs.getData("test", "AGPLv3", function(err, data){
  console.log("Retrieved", err, data); 
});
Parameters:
Name Type Attributes Description
category string

collection from where to read data

dest string

file's destination

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

callback function

function called when retrieving file was completed or errored, providing error object as first param and filedata as second

(static) getHandler() → {object}

Source:

Get handler for connection to close it, for stopping separate scripts

Example
var db = countlyFs.getHandler();
db.close();
Returns:

databse connection

Type
object

(static) getSize(category, dest, optionsopt, callback)

Source:

Get file size

Example
countlyFs.getSize("test", "AGPLv3", function(err, size){
  console.log("Retrieved", err, size); 
});
Parameters:
Name Type Attributes Description
category string

collection from where to read data

dest string

file's destination

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

callback function

function called when retrieving file size was completed or errored, providing error object as first param and file size as second

(static) getStats(category, dest, optionsopt, callback)

Source:

Get file stats

Example
countlyFs.getStats("test", "AGPLv3", function(err, stats){
  //similar to fs.stat object
  console.log("Retrieved", err, stats); 
});
Parameters:
Name Type Attributes Description
category string

collection from where to read data

dest string

file's destination

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

callback function

function called when retrieving file size was completed or errored, providing error object as first param and file size as second

(static) getStream(category, dest, optionsopt, callback)

Source:

Get stream for file

Example
countlyFs.getStream("test", "CHANGELOG.md", function(err, stream){
  var writeStream = fs.createWriteStream('./CHANGELOG.md');    
  stream.pipe(writeStream);
});
Parameters:
Name Type Attributes Description
category string

collection from where to read data

dest string

file's destination

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

callback function

function called when establishing stream was completed or errored, providing error object as first param and stream as second

(static) rename(category, dest, source, optionsopt, callback)

Source:

Move or Rename existing file

Example
countlyFs.rename("test", "AGPLv3", "LICENSE.md", function(err){
  console.log("Finished", err);
});
Parameters:
Name Type Attributes Description
category string

collection where to store data

dest string

file's destination

source string

source file

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

callback function

function called when renaming was completed or errored, providing error object as first param

(static) saveData(category, dest, data, optionsopt, callback)

Source:

Save string data in shared system

Example
countlyFs.saveData("test", "test.text", "some\nmultiline\ntest", function(err){
  console.log("Storing data finished", err);
});
Parameters:
Name Type Attributes Description
category string

collection where to store data

dest string

file's destination

data string

data to save

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

writeMode string

write mode, by default errors on existing file, possible values "overwrite" deleting previous file, or "version", will not work with provided custom id

chunkSizeBytes number

Optional overwrite this bucket's chunkSizeBytes for this file

metadata object

Optional object to store in the file document's metadata field

contentType string

Optional string to store in the file document's contentType field

aliases array

Optional array of strings to store in the file document's aliases field

callback function

function called when saving was completed or errored, providing error object as first param

(static) saveFile(category, dest, source, optionsopt, callback)

Source:

Save file in shared system

Example
countlyFs.saveFile("test", "./CHANGELOG", "./CHANGELOG.md", function(err){
  console.log("Storing file finished", err);
});
Parameters:
Name Type Attributes Description
category string

collection where to store data

dest string

file's destination

source string

source file

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

writeMode string

write mode, by default errors on existing file, possible values "overwrite" deleting previous file, or "version", will not work with provided custom id

chunkSizeBytes number

Optional overwrite this bucket's chunkSizeBytes for this file

metadata object

Optional object to store in the file document's metadata field

contentType string

Optional string to store in the file document's contentType field

aliases array

Optional array of strings to store in the file document's aliases field

callback function

function called when saving was completed or errored, providing error object as first param

(static) saveStream(category, dest, readStream, optionsopt, callback)

Source:

Save file from stream in shared system

Example
countlyFs.saveStream("test", "AGPLv3", fs.createReadStream("AGPLv3"), function(err){
  console.log("Storing stream finished", err);
});
Parameters:
Name Type Attributes Description
category string

collection where to store data

dest string

file's destination

readStream stream

stream where to get file content

options object <optional>

additional options for saving file

Properties
Name Type Description
id string

custom id for the file

writeMode string

write mode, by default errors on existing file, possible values "overwrite" deleting previous file, or "version", will not work with provided custom id

chunkSizeBytes number

Optional overwrite this bucket's chunkSizeBytes for this file

metadata object

Optional object to store in the file document's metadata field

contentType string

Optional string to store in the file document's contentType field

aliases array

Optional array of strings to store in the file document's aliases field

callback function

function called when saving was completed or errored, providing error object as first param

(static) setHandler(dbCon)

Source:

Set handler for connection

Parameters:
Name Type Description
dbCon object

database connection