How to use the buffer.Buffer.concat function in buffer

To help you get started, we’ve selected a few buffer 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 nrkno / tv-automation-atem-connection / src / lib / __tests__ / atemSocket.spec.ts View on Github external
socket.on('error', error)
		socket.on('commandReceived', change)

		const parser = (socket as any)._commandParser as CommandParser
		expect(parser).toBeTruthy()
		const parserSpy = jest.spyOn(parser, 'commandFromRawName')
		expect(parser.version).toEqual(ProtocolVersion.V7_2) // Default

		const expectedCmd1 = new ProgramInputUpdateCommand(0, { source: 0x0123 })
		const expectedCmd2 = new PreviewInputUpdateCommand(1, { source: 0x0444 })

		const testCmd1 = Buffer.from([0, 12, 0, 0, ...Buffer.from(ProgramInputUpdateCommand.rawName, 'ascii'), 0x00, 0x00, 0x01, 0x23])
		const testCmd2 = Buffer.from([0, 12, 0, 0, ...Buffer.from(PreviewInputUpdateCommand.rawName, 'ascii'), 0x01, 0x00, 0x04, 0x44])
		const pktId = 822
		expect(AtemSocketChildSingleton.onCommandReceived).toBeDefined()
		await AtemSocketChildSingleton.onCommandReceived!(Buffer.concat([testCmd1, testCmd2]), pktId)
		await clock.tickAsync(0)

		expect(connect).toHaveBeenCalledTimes(0)
		expect(error).toHaveBeenCalledTimes(0)
		expect(change).toHaveBeenCalledTimes(2)

		expect(parserSpy).toHaveBeenCalledTimes(2)
		expect(parserSpy).toHaveBeenCalledWith(ProgramInputUpdateCommand.rawName)
		expect(parserSpy).toHaveBeenCalledWith(PreviewInputUpdateCommand.rawName)

		// A change with the command
		expect(change).toHaveBeenCalledWith(expectedCmd1)
		expect(change).toHaveBeenCalledWith(expectedCmd2)
	})
	test('receive - empty buffer', async () => {
github DefinitelyTyped / DefinitelyTyped / types / uws / uws-tests.ts View on Github external
}).on('end', () => {
            res.end('You posted me this: ' + Buffer.concat(body).toString());
        });
        // handle some GET url
github pmq20 / node-packer / vendor / node-v7.0.0 / lib / child_process.js View on Github external
if (timeoutId) {
      clearTimeout(timeoutId);
      timeoutId = null;
    }

    if (!callback) return;

    // merge chunks
    var stdout;
    var stderr;
    if (encoding) {
      stdout = _stdout;
      stderr = _stderr;
    } else {
      stdout = Buffer.concat(_stdout);
      stderr = Buffer.concat(_stderr);
    }

    if (ex) {
      // Will be handled later
    } else if (code === 0 && signal === null) {
      callback(null, stdout, stderr);
      return;
    }

    var cmd = file;
    if (args.length !== 0)
      cmd += ' ' + args.join(' ');

    if (!ex) {
      ex = new Error('Command failed: ' + cmd + '\n' + stderr);
github weolar / miniblink49 / node / lib / fs.js View on Github external
// Go ahead and try to read some bytes.
      buffer = Buffer.allocUnsafe(8192);
      bytesRead = tryReadSync(fd, isUserFd, buffer, 0, 8192);
      if (bytesRead !== 0) {
        buffers.push(buffer.slice(0, bytesRead));
      }
      pos += bytesRead;
    } while (bytesRead !== 0);
  }

  if (!isUserFd)
    fs.closeSync(fd);

  if (size === 0) {
    // data was collected into the buffers list.
    buffer = Buffer.concat(buffers, pos);
  } else if (pos < size) {
    buffer = buffer.slice(0, pos);
  }

  if (encoding) buffer = buffer.toString(encoding);
  return buffer;
};
github mceSystems / node-jsc / lib / child_process.js View on Github external
if (timeoutId) {
      clearTimeout(timeoutId);
      timeoutId = null;
    }

    if (!callback) return;

    // merge chunks
    var stdout;
    var stderr;
    if (encoding) {
      stdout = _stdout;
      stderr = _stderr;
    } else {
      stdout = Buffer.concat(_stdout);
      stderr = Buffer.concat(_stderr);
    }

    if (!ex && code === 0 && signal === null) {
      callback(null, stdout, stderr);
      return;
    }

    if (args.length !== 0)
      cmd += ' ' + args.join(' ');

    if (!ex) {
      ex = new Error('Command failed: ' + cmd + '\n' + stderr);
      ex.killed = child.killed || killed;
      ex.code = code < 0 ? uv.errname(code) : code;
      ex.signal = signal;
    }
github w3f / polkadot-deployer / lib / core / cmd.js View on Github external
child.stdout.on('data', (data) => {
        if (options.matcher && options.matcher.test(data)) {
          match = true;
          child.kill('SIGTERM');
          resolve();
          return;
        }
        output = Buffer.concat([output, data]);
        if (options.verbose) {
          console.log(data.toString());
        }
      });
github berty / berty / js / packages / store / chat / outgoingContactRequest.ts View on Github external
const getAggregateId = ({
	contactPk,
	accountId,
}: {
	contactPk: Uint8Array
	accountId: string
}): string => {
	return Buffer.concat([Buffer.from(contactPk), Buffer.from(accountId, 'utf-8')]).toString('base64')
}
github pmq20 / node-packer / vendor / node-v6.8.0 / lib / fs.js View on Github external
function readFileAfterClose(err) {
  var context = this.context;
  var buffer = null;
  var callback = context.callback;

  if (context.err)
    return callback(context.err);

  if (context.size === 0)
    buffer = Buffer.concat(context.buffers, context.pos);
  else if (context.pos < context.size)
    buffer = context.buffer.slice(0, context.pos);
  else
    buffer = context.buffer;

  if (err) return callback(err, buffer);

  if (context.encoding) {
    return tryToString(buffer, context.encoding, callback);
  }

  callback(null, buffer);
}
github a348019017 / 3d_tiles_tools / lib / gltfEx / gltfContainer.ts View on Github external
private mergeBufferToNewBuffer()
    {   
        //按顺序合并成数组
        let bufferArray:Array=this._buffer.positionsAndNormals.buffers.concat(this._buffer.uvs.buffers,this._buffer.vertexs.buffers);  
        let buffer:Buffer=Buffer.concat(bufferArray);
        this._buffers.push(buffer);      
    }
github noobaa / noobaa-core / frontend / src / app / supportability.js View on Github external
gzip.on('end', () => {
            const timestamp = moment(time).format('YYYY_MM_DD-HH_mm_ss');
            const name = `nbfedump.${timestamp}.json.gz`;
            const dump = Buffer.concat(buffers).toString('base64');
            resolve({ name, dump });
        });