How to use the from function from buffer

Find comprehensive JavaScript buffer.from code examples handpicked from public code repositorys.

182
183
184
185
186
187
188
189
190
191
    this.offset = 0;
    var _me = this;
    
    this.fileReader.onloadend = function loaded(event) {
        var data = event.target.result;
        var buf = Buffer.from(data);
        _me.push(buf);
    }
}
util.inherits(FileStream, Stream.Readable);
fork icon227
star icon0
watch icon2

+ 3 other calls in file

14
15
16
17
18
19
20
21
22
23

const expiresInSeconds = Math.ceil(Date.now() / 1000 + expiresInMins * 60);
const toSign = resourceUri + "\n" + expiresInSeconds;

// Use the crypto module to create the hmac.
const hmac = crypto.createHmac("sha256", Buffer.from(signingKey, "base64"));
hmac.update(toSign);
const base64UriEncoded = encodeURIComponent(hmac.digest("base64"));

// Construct authorization string.
fork icon0
star icon0
watch icon1

69
70
71
72
73
74
75
76
77
78
79
80
81
var Buffer = require('buffer').Buffer;


var OurUint8Array = global.Uint8Array || function () {};


function _uint8ArrayToBuffer(chunk) {
  return Buffer.from(chunk);
}


function _isUint8Array(obj) {
  return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
fork icon0
star icon0
watch icon1

227
228
229
230
231
232
233
234
235
236
237
238
  }
}


function zlibBufferSync(engine, buffer) {
  if (typeof buffer === 'string')
    buffer = Buffer.from(buffer);


  if (!Buffer.isBuffer(buffer))
    throw new TypeError('Not a string or buffer');

fork icon0
star icon0
watch icon0

182
183
184
185
186
187
188
189
190
191

// Upload buffer from memory
await page.locator('input#fileElem').setInputFiles({
    name: 'plan.txt',
    mimeType: 'text/plain',
    buffer: Buffer.from(JSON.stringify(json))
});

// Click OK button and wait for Navigate event
await Promise.all([
fork icon0
star icon0
watch icon276

+ 3 other calls in file