From e537f08964e2fcfe94f3777ef75c82f928b65121 Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 19 May 2020 09:20:21 -0400 Subject: Avoide deprecated Buffer constructor --- lib/app.js | 12 ++++++------ lib/serve.js | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/app.js b/lib/app.js index d779b12..b312506 100644 --- a/lib/app.js +++ b/lib/app.js @@ -27,7 +27,7 @@ var Base64URL = require('base64-url') var ssbKeys = require('ssb-keys') var Url = require('url') -var zeros = new Buffer(24); zeros.fill(0) +var zeros = Buffer.alloc(24); zeros.fill(0) module.exports = App @@ -52,8 +52,8 @@ function App(sbot, config) { this.portRegexp = new RegExp(':' + this.ssbPort + '$') this.caps = config.caps || {} this.peerInviteCap = this.caps.peerInvite - || new Buffer('HT0wIYuk3OWc2FtaCfHNnakV68jSGRrjRMP9Kos7IQc=', 'base64') // sha256('peer-invites') - this.devPeerInviteCap = new Buffer('pmr+IzM+4VAZgi5H5bOopXkwnzqrNussS7DtAJsfbf0=', 'base64') // sha256('peer-invites:DEVELOPMENT') + || Buffer.from('HT0wIYuk3OWc2FtaCfHNnakV68jSGRrjRMP9Kos7IQc=', 'base64') // sha256('peer-invites') + this.devPeerInviteCap = Buffer.from('pmr+IzM+4VAZgi5H5bOopXkwnzqrNussS7DtAJsfbf0=', 'base64') // sha256('peer-invites:DEVELOPMENT') this.voteBranches = !!config.voteBranches this.copyableIds = config.copyableIds == null ? true : config.copyableIds @@ -241,8 +241,8 @@ App.prototype.unboxContentWithKey = function (content, key, cb) { if (!key) return this.unboxContent(content, cb) var data try { - var contentBuf = new Buffer(content.replace(/\.box.*$/, ''), 'base64') - var keyBuf = new Buffer(key, 'base64') + var contentBuf = Buffer.from(content.replace(/\.box.*$/, ''), 'base64') + var keyBuf = Buffer.from(key, 'base64') data = PrivateBox.multibox_open_body(contentBuf, keyBuf) if (!data) return cb(new Error('failed to decrypt')) data = JSON.parse(data.toString('utf8')) @@ -476,7 +476,7 @@ App.prototype.getBlob = function (id, key) { } } if (!key) return this.sbot.blobs.get(id) - if (typeof key === 'string') key = new Buffer(key, 'base64') + if (typeof key === 'string') key = Buffer.from(key, 'base64') return pull( this.sbot.blobs.get(id), BoxStream.createUnboxStream(key, zeros) diff --git a/lib/serve.js b/lib/serve.js index 749e075..d292158 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -2090,7 +2090,7 @@ Serve.prototype.blob = function (id, path) { } if (unbox) { try { - key = new Buffer(unbox, 'base64') + key = Buffer.from(unbox, 'base64') } catch(err) { return self.respond(400, err.message) } @@ -2147,14 +2147,14 @@ Serve.prototype.blob = function (id, path) { self.res.writeHead(206) wroteHeaders = true }), - pull.map(Buffer), + pull.map(Buffer.from), self.respondSink() ) } else { pull( self.app.getBlob(id, key), - pull.map(Buffer), + pull.map(Buffer.from), ident(gotType), self.respondSink() ) @@ -2197,7 +2197,7 @@ Serve.prototype.image = function (path) { } if (unbox) { try { - key = new Buffer(unbox, 'base64') + key = Buffer.from(unbox, 'base64') } catch(err) { return self.respond(400, err.message) } @@ -2217,7 +2217,7 @@ Serve.prototype.image = function (path) { pull( self.app.getBlob(id, key), - pull.map(Buffer), + pull.map(Buffer.from), ident(heresTheType), pull.collect(onFullBuffer) ) -- cgit v1.2.3