cloudfunctions/SegmentPortraitPic/node_modules/bson/src/ensure_buffer.ts

(完整代码) 889B

import { Buffer } from 'buffer';
import { BSONTypeError } from './error';
import { isAnyArrayBuffer } from './parser/utils';

/**
 * Makes sure that, if a Uint8Array is passed in, it is wrapped in a Buffer.
 *
 * @param potentialBuffer - The potential buffer
 * @returns Buffer the input if potentialBuffer is a buffer, or a buffer that
 * wraps a passed in Uint8Array
 * @throws BSONTypeError If anything other than a Buffer or Uint8Array is passed in
 */
export function ensureBuffer(potentialBuffer: Buffer | ArrayBufferView | ArrayBuffer): Buffer {
  if (ArrayBuffer.isView(potentialBuffer)) {
    return Buffer.from(
      potentialBuffer.buffer,
      potentialBuffer.byteOffset,
      potentialBuffer.byteLength
    );
  }

  if (isAnyArrayBuffer(potentialBuffer)) {
    return Buffer.from(potentialBuffer);
  }

  throw new BSONTypeError('Must use either Buffer or TypedArray');
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。