Browse Source

Use `Buffer.from()` instead of `new Buffer` (#4)

The `Buffer` constructor is deprecated, we should
use `Buffer.from()` instead.

Refs: https://github.com/nodejs/node/issues/19079
master
Anna Henningsen 6 years ago
committed by Mathias Buus
parent
commit
c7cf5f7d63
  1. 2
      blake2b.js
  2. 7
      example.js

2
blake2b.js

@ -53,7 +53,7 @@ function loadWebAssembly (opts) {
function toUint8Array (s) { function toUint8Array (s) {
if (typeof atob === 'function') return new Uint8Array(atob(s).split('').map(charCodeAt)) if (typeof atob === 'function') return new Uint8Array(atob(s).split('').map(charCodeAt))
return new (require('buf' + 'fer').Buffer)(s, 'base64') return (require('buf' + 'fer').Buffer).from(s, 'base64')
} }
function charCodeAt (c) { function charCodeAt (c) {

7
example.js

@ -1,10 +1,11 @@
'use strict'
var blake2b = require('./') var blake2b = require('./')
blake2b.ready(function () { blake2b.ready(function () {
var hash = blake2b() var hash = blake2b()
.update(new Buffer('hello')) .update(Buffer.from('hello'))
.update(new Buffer(' ')) .update(Buffer.from(' '))
.update(new Buffer('world')) .update(Buffer.from('world'))
.digest('hex') .digest('hex')
console.log('Blake2b hash of "hello world" is %s', hash) console.log('Blake2b hash of "hello world" is %s', hash)

Loading…
Cancel
Save