Skip to content

Commit

Permalink
Add checksum to Logger.
Browse files Browse the repository at this point in the history
Closes #479.
  • Loading branch information
flatheadmill committed Feb 9, 2015
1 parent 9cfba9d commit 542313b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 deletions.
8 changes: 5 additions & 3 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ var cadence = require('cadence/redux')
var Queue = require('./queue')
var Script = require('./script')
var Scribe = require('./scribe')
var checksum = require('./checksum')

function Logger (directory, sheaf) {
this._directory = directory
function Logger (options, sheaf) {
this._directory = options.directory
this._checksum = checksum(options.checksum)
// todo: remove when page can slice
this._sheaf = sheaf
}
Expand All @@ -27,7 +29,7 @@ Logger.prototype.writeEntry = function (options) {

entry = options.header.slice()
json = JSON.stringify(entry)
var hash = this._sheaf.checksum()
var hash = this._checksum()
hash.update(json)

length = 0
Expand Down
16 changes: 0 additions & 16 deletions sheaf.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ function Sheaf (options) {
this.comparator = options.comparator || compare
this.player = options.player
this.logger = options.logger
this.checksum = (function () {
if (typeof options.checksum == 'function') return options.checksum
var algorithm
switch (algorithm = options.checksum || 'sha1') {
case 'none':
return function () {
return {
update: function () {},
digest: function () { return '0' }
}
}
default:
var crypto = require('crypto')
return function (m) { return crypto.createHash(algorithm) }
}
})()
this.serialize = options.serialize || function (object) { return new Buffer(JSON.stringify(object)) }
this.deserialize = options.deserialize || function (buffer) { return JSON.parse(buffer.toString()) }
this.lengths = {}
Expand Down
2 changes: 1 addition & 1 deletion strata.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function extend(to, from) {

function Strata (options) {
options.player = new Player(options)
options.logger = new Logger(options.directory, this.sheaf)
options.logger = new Logger(options, this.sheaf)
options.logger._sheaf = this.sheaf = new Sheaf(options)
}

Expand Down

0 comments on commit 542313b

Please sign in to comment.