Skip to content

Commit

Permalink
added more documentatiooonnnn
Browse files Browse the repository at this point in the history
  • Loading branch information
partkyle committed Feb 11, 2012
1 parent b973e10 commit 858b956
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/file_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ var _ = require('underscore');
var url = require('url');
var fs = require('fs');

/**
* Class to handle file attachments on an email.
*
* @param {object} file_object Options to create a FileHandler
* @param {string} filename The name of the file to send.
* This will be guessed based on the file added
* if blank.
* @param {string} contentType The Content-Type of the file.
* @param {string} content The content to send in the file (usually a Buffer)
* @param {string} path The absolute path of the file on the filesystem
* @param {string} url The url to fetch a file from before sending
*/
function FileHandler(file_object) {
this.filename = file_object.filename;

Expand Down Expand Up @@ -33,12 +45,15 @@ function FileHandler(file_object) {
if (!this.contentType) {
this.contentType = mime.lookup(this.url);
}
} else {this
} else {
this.type = 'none';
this.contentType = 'none';
}
}

/**
* The different methods of loading a file based on the type
*/
FileHandler.handlers = {
content: function(file, callback) {
if (file.content) {
Expand Down Expand Up @@ -95,6 +110,13 @@ FileHandler.handlers = {
}
};

/**
* Loads the content of the file based on the type
* and calls a callback when finished.
*
* @param {function} callback A function to call when
* the result is finished.
*/
FileHandler.prototype.loadContent = function(callback) {
var handler = FileHandler.handlers[this.type];
if (handler) {
Expand Down

0 comments on commit 858b956

Please sign in to comment.