// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

const encoder = new TextEncoder();

function getTypeName(value: unknown): string {
  const type = typeof value;
  if (type !== "object") {
    return type;
  } else if (value === null) {
    return "null";
  } else {
    return value?.constructor?.name ?? "object";
  }
}

export function validateBinaryLike(source: unknown): Uint8Array {
  if (typeof source === "string") {
    return encoder.encode(source);
  } else if (source instanceof Uint8Array) {
    return source;
  } else if (source instanceof ArrayBuffer) {
    return new Uint8Array(source);
  }
  throw new TypeError(
    `The input must be a Uint8Array, a string, or an ArrayBuffer. Received a value of the type ${
      getTypeName(source)
    }.`,
  );
}

// denoCacheMetadata={"headers":{"cross-origin-embedder-policy":"same-origin","server-timing":"fetchSource;dur=7","x-frame-options":"DENY","access-control-allow-methods":"GET, HEAD","date":"Tue, 07 Jul 2026 15:48:36 GMT","referrer-policy":"strict-origin-when-cross-origin","x-amz-replication-status":"COMPLETED","x-amz-cf-pop":"ORD56-P16","etag":"\"d13b3b0dcf6d4f86b4aed186221caac0\"","x-amz-server-side-encryption":"AES256","access-control-max-age":"0","content-type":"application/typescript; charset=utf-8","alt-svc":"h3=\":443\"; ma=86400","access-control-allow-origin":"*","age":"1802558","via":"1.1 8267ddda05eecda7c23d647573952fee.cloudfront.net (CloudFront),HTTP/2 ord.vultr.prod.deno-cluster.net","server":"AmazonS3,deployd","x-amz-version-id":"8jOB.Lq1pZdFojXtsQ2Dcv9jcjkatOqN","accept-ranges":"bytes","cache-control":"public, max-age=31536000, immutable","content-security-policy":"default-src 'none'; style-src 'unsafe-inline'; sandbox","cross-origin-resource-policy":"same-origin","last-modified":"Thu, 25 Apr 2024 03:01:09 GMT","cross-origin-opener-policy":"same-origin","content-length":"798","x-amz-cf-id":"XFIL7HjLxvPFWj4If7fbBW5PSLjX9Mc8ytwLeUtPkHw2SQ1E8LXffQ==","cache-status":"deno; hit","x-content-type-options":"nosniff","x-deno-trace-id":"861c85ee24e496f1a9dd5e6afeb1ef4f","strict-transport-security":"max-age=63072000; includeSubDomains; preload","x-cache":"Hit from cloudfront"},"url":"https://deno.land/std@0.224.0/encoding/_util.ts","time":1785241873}