// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.

/**
 * Concatenate an array of byte slices into a single slice.
 *
 * @param buffers Array of byte slices to concatenate.
 * @returns Hello
 *
 * @example Basic usage
 * ```ts
 * import { concat } from "@std/bytes/concat";
 *
 * const a = new Uint8Array([0, 1, 2]);
 * const b = new Uint8Array([3, 4, 5]);
 *
 * concat([a, b]); // Uint8Array(6) [ 0, 1, 2, 3, 4, 5 ]
 * ```
 */
export function concat(buffers: Uint8Array[]): Uint8Array {
  let length = 0;
  for (const buffer of buffers) {
    length += buffer.length;
  }
  const output = new Uint8Array(length);
  let index = 0;
  for (const buffer of buffers) {
    output.set(buffer, index);
    index += buffer.length;
  }

  return output;
}

// denoCacheMetadata={"headers":{"cf-cache-status":"HIT","access-control-expose-headers":"*","date":"Tue, 28 Jul 2026 12:31:14 GMT","content-type":"text/typescript","cf-ray":"a223e6564ec67db6-LAX","x-content-type-options":"nosniff","content-length":"811","set-cookie":"__cf_bm=sr3wf1I5UkyW1oNKlCJlcRe5rIuu.ujbWTJaVjRwLkY-1785241874.9439297-1.0.1.1-x6keK3HTkmYPAyfJl8Y0caFN4n1q0JuC1cc3bG06.UG8MmmLUZEnSgtXrA1vrwjCQRZDzw9tMwXPdkA9pqmgxvhHQJkZo4U0Le_nP65al532aPkKYKC2Dhs_lTe0BHey; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:14 GMT","cache-control":"public, max-age=31536000, immutable","etag":"\"22d34068e688f3dd7900c1b8d957a4a0\"","server":"cloudflare","cross-origin-resource-policy":"cross-origin","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=PucFAEq0N4QdwYFm%2BnUBD8cquPWTfi7mMlbb2uBj5sHg%2F%2BL69dxyOUcBG8dCtvMyuhMTlRn8%2FxDDeSYd9U63dGXExgxRNEtElbdayBoeIxKOKoSYjetui84%3D\"}]}","x-jsr-backend":"modules","vary":"Origin","content-security-policy":"default-src 'none'; script-src 'none'; style-src 'none'; img-src 'none'; font-src 'none'; connect-src 'none'; frame-src 'none'; object-src 'none'; frame-ancestors 'none'; sandbox; form-action 'none';","alt-svc":"h3=\":443\"; ma=86400","access-control-allow-origin":"*","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","age":"4259242","accept-ranges":"bytes","x-robots-tag":"noindex"},"url":"https://jsr.io/@std/bytes/0.224.0/concat.ts","time":1785241874}