How to use the buffer.Buffer.from 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 graalvm / graaljs / lib / child_process.js View on Github external
options.stdio = getValidStdio(options.stdio || 'pipe', true).stdio;

  if (options.input) {
    var stdin = options.stdio[0] = { ...options.stdio[0] };
    stdin.input = options.input;
  }

  // We may want to pass data in on any given fd, ensure it is a valid buffer
  for (var i = 0; i < options.stdio.length; i++) {
    var input = options.stdio[i] && options.stdio[i].input;
    if (input != null) {
      var pipe = options.stdio[i] = { ...options.stdio[i] };
      if (isArrayBufferView(input)) {
        pipe.input = input;
      } else if (typeof input === 'string') {
        pipe.input = Buffer.from(input, options.encoding);
      } else {
        throw new ERR_INVALID_ARG_TYPE(`options.stdio[${i}]`,
                                       ['Buffer',
                                        'TypedArray',
                                        'DataView',
                                        'string'],
                                       input);
      }
    }
  }

  return child_process.spawnSync(opts);
}
github MrTreasure / ts-koa / test / crypto.spec.ts View on Github external
test('公钥密码', () => {
    const publicText = crypto.publicEncrypt(publicKey, Buffer.from(plainText))
    const privateText = crypto.privateDecrypt(privateKey, publicText)
    expect(privateText.toString()).toBe(plainText)
  })
github peerlinks / peerlinks-server / lib / service.js View on Github external
async function checkAuth(req) {
    const auth = req.headers.authorization || '';
    if (!auth) {
      return false;
    }

    const match = auth.match(/^bearer\s+([^\s]+)\s*$/i);
    if (!match) {
      return false;
    }

    const reqToken = Buffer.from(match[1]);
    if (reqToken.length !== httpToken.length) {
      return false;
    }

    return timingSafeEqual(reqToken, httpToken);
  }
github decentralized-identity / did-jwt / src / SignerAlgorithm.ts View on Github external
function toJose ({ r, s, recoveryParam }) {
    const jose = Buffer.alloc(recoverable ? 65 : 64)
    Buffer.from(r, 'hex').copy(jose, 0)
    Buffer.from(s, 'hex').copy(jose, 32)
    if (recoverable) {
      if (recoveryParam === undefined) throw new Error('Signer did not return a recoveryParam')
      jose[64] = recoveryParam
    }
    return base64url.encode(jose)
  }
github ehmicky / autoserver / gulp / tasks / build / format.js View on Github external
const getContents = function ({
  destFormat,
  file: { contents, path },
}) {
  const srcFormat = getByExt({ path });

  const content = contents.toString();

  const contentA = srcFormat.parseContent(content, { path });
  const contentB = destFormat.serializeContent(contentA);

  const contentC = Buffer.from(contentB);
  return contentC;
};
github pmq20 / node-packer / vendor / node / lib / fs.js View on Github external
function encodeRealpathResult(result, options, err) {
  if (!options || !options.encoding || options.encoding === 'utf8' || err)
    return result;
  const asBuffer = Buffer.from(result);
  if (options.encoding === 'buffer') {
    return asBuffer;
  } else {
    return asBuffer.toString(options.encoding);
  }
}
github textileio / react-native-sdk / src / util-internal.ts View on Github external
return {
        type,
        block,
        value: Ignore.decode(Buffer.from(data, 'base64'))
      }
    case FeedItemType.Join:
      return {
        type,
        block,
        value: Join.decode(Buffer.from(data, 'base64'))
      }
    case FeedItemType.Leave:
      return {
        type,
        block,
        value: Leave.decode(Buffer.from(data, 'base64'))
      }
    case FeedItemType.Announce:
      return {
        type,
        block,
        value: Announce.decode(Buffer.from(data, 'base64'))
      }
  }
}
github textileio / react-native-sdk / src / files.ts View on Github external
export async function file(blockId: string): Promise {
  const result = await FilesBridge.file(blockId)
  return Files.decode(Buffer.from(result, 'base64'))
}