Remove hashlib dependency and switch to mocha for testing

This commit is contained in:
John Crepezzi 2012-01-13 11:16:42 -05:00
parent b251978422
commit 6e4c087319
7 changed files with 42 additions and 65 deletions

View file

@ -1,7 +1,7 @@
var fs = require('fs');
var crypto = require('crypto');
var winston = require('winston');
var hashlib = require('hashlib');
// For storing in files
// options[type] = file
@ -12,12 +12,19 @@ var FileDocumentStore = function(options) {
this.expire = options.expire;
};
// Generate md5 of a string
FileDocumentStore.md5 = function(str) {
var md5sum = crypto.createHash('md5');
md5sum.update(str);
return md5sum.digest('hex');
};
// Save data in a file, key as md5 - since we don't know what we could be passed here
FileDocumentStore.prototype.set = function(key, data, callback, skipExpire) {
try {
var _this = this;
fs.mkdir(this.basePath, '700', function() {
fs.writeFile(_this.basePath + '/' + hashlib.md5(key), data, 'utf8', function(err) {
fs.writeFile(_this.basePath + '/' + _this.md5(key), data, 'utf8', function(err) {
if (err) {
callback(false);
}
@ -37,7 +44,7 @@ FileDocumentStore.prototype.set = function(key, data, callback, skipExpire) {
// Get data from a file from key
FileDocumentStore.prototype.get = function(key, callback, skipExpire) {
var _this = this;
fs.readFile(this.basePath + '/' + hashlib.md5(key), 'utf8', function(err, data) {
fs.readFile(this.basePath + '/' + _this..md5(key), 'utf8', function(err, data) {
if (err) {
callback(false);
}