Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utf8 as default encoding #4

Merged
merged 1 commit into from
May 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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