How to use buffer-alloc - 4 common examples

To help you get started, we’ve selected a few buffer-alloc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sfast / zeronode / src / sockets / envelope.js View on Github external
static stringToBuffer (str, encryption) {
    let strLength = Buffer.byteLength(str, encryption)
    let lengthBuffer = BufferAlloc(lengthSize)
    lengthBuffer.writeInt8(strLength)
    let strBuffer = BufferAlloc(strLength)
    strBuffer.write(str, 0, strLength, encryption)
    return Buffer.concat([lengthBuffer, strBuffer])
  }
github sfast / zeronode / src / sockets / envelope.js View on Github external
getBuffer () {
    let bufferArray = []

    let mainEventBuffer = BufferAlloc(1)
    mainEventBuffer.writeInt8(+this.mainEvent)
    bufferArray.push(mainEventBuffer)

    let typeBuffer = BufferAlloc(1)
    typeBuffer.writeInt8(this.type)
    bufferArray.push(typeBuffer)

    let idBuffer = Envelop.stringToBuffer(this.id.toString(), 'hex')
    bufferArray.push(idBuffer)

    let ownerBuffer = Envelop.stringToBuffer(this.owner.toString(), 'utf-8')
    bufferArray.push(ownerBuffer)

    let recipientBuffer = Envelop.stringToBuffer(this.recipient.toString(), 'utf-8')
    bufferArray.push(recipientBuffer)

    let tagBuffer = Envelop.stringToBuffer(this.tag.toString(), 'utf-8')
    bufferArray.push(tagBuffer)

    if (this.data) {
github sfast / zeronode / src / sockets / envelope.js View on Github external
static stringToBuffer (str, encryption) {
    let strLength = Buffer.byteLength(str, encryption)
    let lengthBuffer = BufferAlloc(lengthSize)
    lengthBuffer.writeInt8(strLength)
    let strBuffer = BufferAlloc(strLength)
    strBuffer.write(str, 0, strLength, encryption)
    return Buffer.concat([lengthBuffer, strBuffer])
  }
github sfast / zeronode / src / sockets / envelope.js View on Github external
getBuffer () {
    let bufferArray = []

    let mainEventBuffer = BufferAlloc(1)
    mainEventBuffer.writeInt8(+this.mainEvent)
    bufferArray.push(mainEventBuffer)

    let typeBuffer = BufferAlloc(1)
    typeBuffer.writeInt8(this.type)
    bufferArray.push(typeBuffer)

    let idBuffer = Envelop.stringToBuffer(this.id.toString(), 'hex')
    bufferArray.push(idBuffer)

    let ownerBuffer = Envelop.stringToBuffer(this.owner.toString(), 'utf-8')
    bufferArray.push(ownerBuffer)

    let recipientBuffer = Envelop.stringToBuffer(this.recipient.toString(), 'utf-8')
    bufferArray.push(recipientBuffer)

buffer-alloc

A [ponyfill](https://ponyfill.com) for `Buffer.alloc`.

MIT
Latest version published 6 years ago

Package Health Score

65 / 100
Full package analysis

Popular buffer-alloc functions