Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/bytes/copy.ts>copy

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function copy
import { copy } from "https://deno.land/std@0.220.1/bytes/copy.ts";

Copy bytes from the src array to the dst array. Returns the number of bytes copied.

If the src array is larger than what the dst array can hold, only the amount of bytes that fit in the dst array are copied.

An offset can be specified as the third argument that begins the copy at that given index in the dst array. The offset defaults to the beginning of the array.

import { copy } from "https://deno.land/std@0.220.1/bytes/copy.ts";
const src = new Uint8Array([9, 8, 7]);
const dst = new Uint8Array([0, 1, 2, 3, 4, 5]);
console.log(copy(src, dst)); // 3
console.log(dst); // [9, 8, 7, 3, 4, 5]
import { copy } from "https://deno.land/std@0.220.1/bytes/copy.ts";
const src = new Uint8Array([1, 1, 1, 1]);
const dst = new Uint8Array([0, 0, 0, 0]);
console.log(copy(src, dst, 1)); // 3
console.log(dst); // [0, 1, 1, 1]

Parameters

src: Uint8Array
dst: Uint8Array
optional
off = [UNSUPPORTED]

Returns

number