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

/**
 * Slice number into 64bit big endian byte array.
 *
 * @example Usage
 * ```ts
 * import { sliceLongToBytes } from "@std/io/slice-long-to-bytes";
 * import { assertEquals } from "@std/assert/equals";
 *
 * const dest = sliceLongToBytes(0x123456789a);
 * assertEquals(dest, [0, 0, 0, 0x12, 0x34, 0x56, 0x78, 0x9a]);
 * ```
 *
 * @param d The number to be sliced
 * @param dest The array to store the sliced bytes
 * @returns The sliced bytes
 *
 * @deprecated This will be removed in 1.0.0. Use the {@link https://developer.mozilla.org/en-US/docs/Web/API/Streams_API | Web Streams API} instead.
 */
export function sliceLongToBytes(
  d: number,
  dest: number[] = Array.from<number>({ length: 8 }),
): number[] {
  let big = BigInt(d);
  for (let i = 0; i < 8; i++) {
    dest[7 - i] = Number(big & 0xffn);
    big >>= 8n;
  }
  return dest;
}

// denoCacheMetadata={"headers":{"access-control-allow-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';","cross-origin-resource-policy":"cross-origin","access-control-expose-headers":"*","x-jsr-backend":"modules","x-robots-tag":"noindex","set-cookie":"__cf_bm=L0NeD._PTenUEtzvJiZryfdeeas1X7llp6S6T7Bzv0I-1785241875.0645916-1.0.1.1-tfuSS0pAlRQ60.IawUYIdU8jx.k67O2tMY0x9wbRMybDnQmTBh4nhQIXwp3lsQyDbMCtwqQN06zD5eOhoO3P8M2.P6SuuvhIbzjF.ZUQJSGSgAM9S88NAkyA2IRUH_u_; HttpOnly; SameSite=None; Secure; Path=/; Domain=jsr.io; Expires=Tue, 28 Jul 2026 13:01:15 GMT","report-to":"{\"group\":\"cf-nel\",\"max_age\":604800,\"endpoints\":[{\"url\":\"https://a.nel.cloudflare.com/report/v4?s=%2BayXLkSuVoFk0%2FUViP55YGiyUP07ddESTT8K3a4rq9fdqaAMPkL1f628BMzNuV3AT7DzJYi1fujzcWcgUZqd83NmjdNDN3UqMH8aJ8EaDcaXjAq4hkZvxx8%3D\"}]}","x-content-type-options":"nosniff","content-length":"963","server":"cloudflare","nel":"{\"report_to\":\"cf-nel\",\"success_fraction\":0.0,\"max_age\":604800}","cache-control":"public, max-age=31536000, immutable","date":"Tue, 28 Jul 2026 12:31:15 GMT","vary":"Origin","etag":"\"b0843dd5948f27f11d92957317925f63\"","content-type":"text/typescript","cf-ray":"a223e65728e17db6-LAX","alt-svc":"h3=\":443\"; ma=86400"},"url":"https://jsr.io/@std/io/0.224.8/slice_long_to_bytes.ts","time":1785241875}