How to use @aws-sdk/util-buffer-from - 10 common examples

To help you get started, we’ve selected a few @aws-sdk/util-buffer-from 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 / hash-node / src / index.spec.ts View on Github external
it("should accept string data", async () => {
    const hash = new Hash("md5");
    hash.update("");
    const { buffer } = await hash.digest();
    expect(fromArrayBuffer(buffer).toString("hex")).toBe(
      "d41d8cd98f00b204e9800998ecf8427e"
    );
  });
github aws / aws-sdk-js-v3 / packages / hash-node / src / index.spec.ts View on Github external
it(`should calculate a ${supportedHash} hmac of ${expected} for an input of ${data} and a key of ${key}`, async () => {
          const hash = new Hash(supportedHash, fromString(key, "hex"));
          hash.update(fromString(data, "hex"));
          const { buffer } = await hash.digest();
          expect(fromArrayBuffer(buffer).toString("hex")).toMatch(expected);
        });
      }
github aws / aws-sdk-js-v3 / packages / hash-node / src / index.spec.ts View on Github external
it(`should calculate a ${supportedHash} hash of ${expected} for an input of ${input}`, async () => {
          const hash = new Hash(supportedHash);
          hash.update(fromString(input, "base64"));
          const { buffer } = await hash.digest();
          expect(fromArrayBuffer(buffer).toString("hex")).toBe(expected);
        });
      }
github aws / aws-sdk-js-v3 / packages / hash-node / src / index.spec.ts View on Github external
it(`should calculate a ${supportedHash} hmac of ${expected} for an input of ${data} and a key of ${key}`, async () => {
          const hash = new Hash(supportedHash, fromString(key, "hex"));
          hash.update(fromString(data, "hex"));
          const { buffer } = await hash.digest();
          expect(fromArrayBuffer(buffer).toString("hex")).toMatch(expected);
        });
      }
github aws / aws-sdk-js-v3 / packages / hash-node / src / index.ts View on Github external
function castSourceData(toCast: SourceData, encoding?: string): Buffer {
  if (Buffer.isBuffer(toCast)) {
    return toCast;
  }

  if (typeof toCast === "string") {
    return fromString(toCast, encoding);
  }

  if (ArrayBuffer.isView(toCast)) {
    return fromArrayBuffer(toCast.buffer, toCast.byteOffset, toCast.byteLength);
  }

  return fromArrayBuffer(toCast);
}
github aws / aws-sdk-js-v3 / packages / hash-node / src / index.ts View on Github external
function castSourceData(toCast: SourceData, encoding?: string): Buffer {
  if (Buffer.isBuffer(toCast)) {
    return toCast;
  }

  if (typeof toCast === "string") {
    return fromString(toCast, encoding);
  }

  if (ArrayBuffer.isView(toCast)) {
    return fromArrayBuffer(toCast.buffer, toCast.byteOffset, toCast.byteLength);
  }

  return fromArrayBuffer(toCast);
}
github aws / aws-sdk-js-v3 / packages / util-utf8-node / src / index.ts View on Github external
export function toUtf8(input: Uint8Array): string {
  return fromArrayBuffer(
    input.buffer,
    input.byteOffset,
    input.byteLength
  ).toString("utf8");
}
github aws / aws-sdk-js-v3 / packages / util-base64-node / src / index.ts View on Github external
export function toBase64(input: Uint8Array): string {
  return fromArrayBuffer(
    input.buffer,
    input.byteOffset,
    input.byteLength
  ).toString("base64");
}
github aws / aws-sdk-js-v3 / packages / util-utf8-node / src / index.ts View on Github external
export function fromUtf8(input: string): Uint8Array {
  const buf = fromString(input, "utf8");

  return new Uint8Array(
    buf.buffer,
    buf.byteOffset,
    buf.byteLength / Uint8Array.BYTES_PER_ELEMENT
  );
}
github aws / aws-sdk-js-v3 / packages / hash-node / src / index.ts View on Github external
function castSourceData(toCast: SourceData, encoding?: string): Buffer {
  if (Buffer.isBuffer(toCast)) {
    return toCast;
  }

  if (typeof toCast === "string") {
    return fromString(toCast, encoding);
  }

  if (ArrayBuffer.isView(toCast)) {
    return fromArrayBuffer(toCast.buffer, toCast.byteOffset, toCast.byteLength);
  }

  return fromArrayBuffer(toCast);
}

@aws-sdk/util-buffer-from

[![NPM version](https://img.shields.io/npm/v/@aws-sdk/util-buffer-from/latest.svg)](https://www.npmjs.com/package/@aws-sdk/util-buffer-from) [![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/util-buffer-from.svg)](https://www.npmjs.com/package/@aws

Apache-2.0
Latest version published 1 year ago

Package Health Score

72 / 100
Full package analysis

Similar packages