Skip to content

Commit

Permalink
utf8 as default encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Apr 29, 2016
1 parent dff2ded commit 5d95d75
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_js:
- "0.12"
- "4"
- "5"
- "6"
env:
matrix:
- TEST_SUITE=unit
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ HashBase.prototype._flush = function (callback) {
HashBase.prototype.update = function (data, encoding) {
if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')
if (this._finalized) throw new Error('Digest already called')
if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding || 'binary')
if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding)

// consume data
var block = this._block
Expand Down
8 changes: 5 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'
var test = require('tape').test
var test = require('tape')
var HashBase = require('../')

function beforeEach (t) {
Expand Down Expand Up @@ -87,11 +87,13 @@ test('update', function (t) {
t.end()
})

t.test('decode string with binary by default', function (t) {
t.test('decode string with utf8 by default', function (t) {
t.plan(1)
var buffer = new Buffer(64)
buffer.fill(0)
new Buffer('УТФ-8', 'utf8').copy(buffer)
t.base._update = function () { t.same(this._block, buffer) }
t.base.update(buffer.toString('binary'))
t.base.update(buffer.toString('utf8'))
t.end()
})

Expand Down

0 comments on commit 5d95d75

Please sign in to comment.