import { copy } from "./copy.ts";
export function repeat(source: Uint8Array, count: number): Uint8Array { if (count === 0) { return new Uint8Array(); }
if (count < 0) { throw new RangeError("bytes: negative repeat count"); } else if ((source.length * count) / count !== source.length) { throw new Error("bytes: repeat count causes overflow"); }
const int = Math.floor(count);
if (int !== count) { throw new Error("bytes: repeat count must be an integer"); }
const nb = new Uint8Array(source.length * count);
let bp = copy(source, nb);
for (; bp < nb.length; bp *= 2) { copy(nb.slice(0, bp), nb, bp); }
return nb;}