How to use the alloc function from safe-buffer
Find comprehensive JavaScript safe-buffer.alloc code examples handpicked from public code repositorys.
5 6 7 8 9 10 11 12 13 14
// Mostly taken from Fermata.js // https://github.com/natevw/fermata/blob/5d9732a33d776ce925013a265935facd1626cc88/fermata.js#L315-L343 function multipartDataGenerator(method, data, headers) { var segno = (Math.round(Math.random() * 1e16) + Math.round(Math.random() * 1e16)).toString(); headers['Content-Type'] = ('multipart/form-data; boundary=' + segno); var buffer = Buffer.alloc(0); function push(l) { var prevBuffer = buffer; var newBuffer = (l instanceof Buffer) ? l : Buffer.from(l);
+ 23 other calls in file
83 84 85 86 87 88 89 90 91 92
var zeros = Buffer.alloc(q.byteLength() - x.length) x = Buffer.concat([zeros, x]) } var hlen = hash.length var hbits = bits2octets(hash, q) var v = Buffer.alloc(hlen) v.fill(1) var k = Buffer.alloc(hlen) k = createHmac(algo, k).update(v).update(Buffer.from([0])).update(x).update(hbits).digest() v = createHmac(algo, k).update(v).digest()
+ 4 other calls in file
38 39 40 41 42 43 44 45 46 47 48 49
// You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA var Buffer = require('safe-buffer').Buffer var ZEROES = Buffer.alloc(16, 0) function toArray (buf) { return [ buf.readUInt32BE(0),
GitHub: velas/mobile-wallet
![velas profile picture](/velas.png?size=40)
68 69 70 71 72 73 74 75 76 77
var ret = []; var i = 0; while (Buffer.concat(ret).length < keysize + ivsize) { ret[i] = iter(i === 0 ? Buffer.alloc(0) : ret[i - 1]); i++; } var tmp = Buffer.concat(ret);
+ 7 other calls in file
4874 4875 4876 4877 4878 4879 4880 4881 4882 4883
ret += s + p.data; }return ret; }; BufferList.prototype.concat = function concat(n) { if (this.length === 0) return Buffer.alloc(0); if (this.length === 1) return this.head.data; var ret = Buffer.allocUnsafe(n >>> 0); var p = this.head; var i = 0;
8699 8700 8701 8702 8703 8704 8705 8706 8707 8708
},{"buffer":"buffer"}],54:[function(require,module,exports){ var Buffer = require('safe-buffer').Buffer // prototype class for hash functions function Hash (blockSize, finalSize) { this._block = Buffer.alloc(blockSize) this._finalSize = finalSize this._blockSize = blockSize this._len = 0 }
GitHub: thenikso/tu
487 488 489 490 491 492 493 494 495 496 497 498
function SlowBuffer (length) { if (+length != length) { // eslint-disable-line eqeqeq length = 0 } return Buffer.alloc(+length) } Buffer.isBuffer = function isBuffer (b) { return b != null && b._isBuffer === true &&
+ 20 other calls in file
GitHub: blockconsortium/bip39
![blockconsortium profile picture](/blockconsortium.png?size=40)
100 101 102 103 104 105 106 107 108 109
return str } function decodeUnsafe (source) { if (typeof source !== 'string') throw new TypeError('Expected String') if (source.length === 0) return Buffer.alloc(0) let psz = 0 // Skip leading spaces.
4467 4468 4469 4470 4471 4472 4473 4474 4475 4476
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) } return str } function decodeUnsafe (source) { if (typeof source !== 'string') { throw new TypeError('Expected String') } if (source.length === 0) { return _Buffer.alloc(0) } var psz = 0 // Skip and count leading '1's. var zeroes = 0 var length = 0
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
debug('invalid JSON received', self.uri.href) } } debug('emitting complete', self.uri.href) if (typeof response.body === 'undefined' && !self._json) { response.body = self.encoding === null ? Buffer.alloc(0) : '' } self.emit('complete', response, response.body) }) }
+ 6 other calls in file
145 146 147 148 149 150 151 152 153 154
}) }) describe('with limit option', function () { it('should 413 when over limit with Content-Length', function (done) { var buf = Buffer.alloc(1024, '.') request(createApp({ limit: '1kb' })) .post('/') .set('Content-Type', 'application/json') .set('Content-Length', '1034')
+ 29 other calls in file
12 13 14 15 16 17 18 19 20 21
a_ = a b.copy(padded, padded.length-b.length) b_ = padded } else if(a.length < b.length){ padded = Buffer.alloc(b.length) a_ = a.copy(padded, padded.length-a.length) a_ = padded b_ = b } else {
+ 3 other calls in file
740 741 742 743 744 745 746 747 748 749 750 751
}; var read = function(self, length, buffer, options, callback) { // The data is a c-terminated string and thus the length - 1 var finalLength = length == null ? self.length - self.position : length; var finalBuffer = buffer == null ? Buffer.alloc(finalLength) : buffer; // Add a index to buffer to keep track of writing position or apply current index finalBuffer._index = buffer != null && buffer._index != null ? buffer._index : 0; if (self.currentChunk.length() - self.currentChunk.position + finalBuffer._index >= finalLength) {
4251 4252 4253 4254 4255 4256 4257 4258 4259 4260
case 'text': response = xhr.responseText if (response.length > self._pos) { var newData = response.substr(self._pos) if (self._charset === 'x-user-defined') { var buffer = Buffer.alloc(newData.length) for (var i = 0; i < newData.length; i++) buffer[i] = newData.charCodeAt(i) & 0xff self.push(buffer)
+ 3 other calls in file
GitHub: HETONGAPP/src
5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638
exports.MAGICNUMBER = 0x184D2204 exports.MAGICNUMBER_BUFFER = Buffer.alloc(4) exports.MAGICNUMBER_BUFFER.writeUInt32LE(exports.MAGICNUMBER, 0) exports.EOS = 0 exports.EOS_BUFFER = Buffer.alloc(4) exports.EOS_BUFFER.writeUInt32LE(exports.EOS, 0) exports.VERSION = 1
+ 19 other calls in file
safe-buffer.from is the most popular function in safe-buffer (2601 examples)