How to use the @aws-sdk/is-array-buffer.isArrayBuffer function in @aws-sdk/is-array-buffer

To help you get started, we’ve selected a few @aws-sdk/is-array-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 aws / aws-sdk-js-v3 / packages / util-buffer-from / src / index.ts View on Github external
export function fromArrayBuffer(
  input: ArrayBuffer,
  offset: number = 0,
  length: number = input.byteLength - offset
): Buffer {
  if (!isArrayBuffer(input)) {
    throw new Error(
      "argument passed to fromArrayBuffer was not an ArrayBuffer"
    );
  }

  if (typeof Buffer.from === "function" && Buffer.from !== Uint8Array.from) {
    return Buffer.from(input, offset, length);
  }

  // Any version of node that supports the optional offset and length
  // parameters, which were added in Node 6.0.0, will support Buffer.from and
  // have already returned. Throw if offset is not 0 or if length differs from
  // the underlying buffer's length.
  if (offset !== 0 || length !== input.byteLength) {
    throw new Error(
      `Unable to convert TypedArray to Buffer in Node ${process.version}`
github aws / aws-sdk-js-v3 / packages / signature-v4 / src / getPayloadHash.ts View on Github external
export async function getPayloadHash(
  { headers, body }: HttpRequest,
  hashConstructor: HashConstructor
): Promise {
  for (const headerName of Object.keys(headers)) {
    if (headerName.toLowerCase() === SHA256_HEADER) {
      return headers[headerName];
    }
  }

  if (body == undefined) {
    return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
  } else if (
    typeof body === "string" ||
    ArrayBuffer.isView(body) ||
    isArrayBuffer(body)
  ) {
    const hashCtor = new hashConstructor();
    hashCtor.update(body);
    return toHex(await hashCtor.digest());
  }

  // As any defined body that is not a string or binary data is a stream, this
  // body is unsignable. Attempt to send the request with an unsigned payload,
  // which may or may not be accepted by the service.
  return UNSIGNED_PAYLOAD;
}
github aws / aws-sdk-js-v3 / packages / protocol-json-rpc / src / JsonRpcParser.ts View on Github external
private resolveBodyString(input: HttpResponse): Promise {
    const { body = "" } = input;
    if (typeof body === "string") {
      return Promise.resolve(body);
    }

    let bufferPromise: Promise;
    if (ArrayBuffer.isView(body)) {
      bufferPromise = Promise.resolve(
        new Uint8Array(body.buffer, body.byteLength, body.byteOffset)
      );
    } else if (isArrayBuffer(body)) {
      bufferPromise = Promise.resolve(new Uint8Array(body, 0, body.byteLength));
    } else {
      bufferPromise = this.bodyCollector(body);
    }

    return bufferPromise.then(buffer => this.utf8Encoder(buffer));
  }
}
github aws / aws-sdk-js-v3 / packages / middleware-apply-body-checksum / src / applyMd5BodyChecksumMiddleware.ts View on Github external
): BuildHandler => async (
    args: BuildHandlerArguments
  ): Promise> => {
    let { request } = args;
    if (HttpRequest.isInstance(request)) {
      const { body, headers } = request;
      if (!hasHeader("Content-MD5", headers)) {
        let digest: Promise;
        if (
          body === undefined ||
          typeof body === "string" ||
          ArrayBuffer.isView(body) ||
          isArrayBuffer(body)
        ) {
          const hash = new options.md5();
          hash.update(body || "");
          digest = hash.digest();
        } else {
          digest = options.streamHasher(options.md5, body);
        }

        request = {
          ...request,
          headers: {
            ...headers,
            "Content-MD5": options.base64Encoder(await digest)
          }
        };
      }
github aws / aws-sdk-js-v3 / packages / protocol-rest / src / RestParser.ts View on Github external
private resolveBody(
    body: HttpResponse["body"] = ""
  ): Promise {
    if (typeof body === "string") {
      return Promise.resolve(body);
    }

    let bufferPromise: Promise;
    if (ArrayBuffer.isView(body)) {
      bufferPromise = Promise.resolve(
        new Uint8Array(body.buffer, body.byteOffset, body.byteLength)
      );
    } else if (isArrayBuffer(body)) {
      bufferPromise = Promise.resolve(new Uint8Array(body, 0, body.byteLength));
    } else {
      bufferPromise = this.bodyCollector(body);
    }

    return bufferPromise;
  }
github aws / aws-sdk-js-v3 / packages / http-serialization / src / index.ts View on Github external
function serializeBody(message: HttpMessage): string {
  if (message.body === undefined) {
    return "";
  }

  if (typeof message.body === "string") {
    return message.body;
  }

  if (ArrayBuffer.isView(message.body) || isArrayBuffer(message.body)) {
    return "[binary payload]";
  }

  return "[streaming payload]";
}
github aws / aws-sdk-js-v3 / packages / query-builder / src / index.ts View on Github external
private serializeBlob(prefix: string, input: any, shape: Blob): string {
    if (typeof input === "string") {
      input = this.utf8Decoder(input);
    } else if (ArrayBuffer.isView(input)) {
      input = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
    } else if (isArrayBuffer(input)) {
      input = new Uint8Array(input);
    } else {
      throw new Error(
        "Unable to serialize value that is neither a string nor an" +
          " ArrayBuffer nor an ArrayBufferView as a blob"
      );
    }

    return `${prefix}=${this.base64Encoder(input)}`;
  }

@aws-sdk/is-array-buffer

Provides a function for detecting if an argument is an ArrayBuffer

Apache-2.0
Latest version published 1 year ago

Package Health Score

72 / 100
Full package analysis

Popular @aws-sdk/is-array-buffer functions