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

x/proc/legacy/deps.ts>readRange

A better way to work with processes in Deno.
Go to Latest
function readRange
Deprecated
Deprecated

(will be removed after 1.0.0) Use the [Web Streams API]https://developer.mozilla.org/en-US/docs/Web/API/Streams_API instead.

import { readRange } from "https://deno.land/x/proc@0.21.5/legacy/deps.ts";

Read a range of bytes from a file or other resource that is readable and seekable. The range start and end are inclusive of the bytes within that range.

import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";
import { readRange } from "https://deno.land/std@0.224.0/io/read_range.ts";

// Read the first 10 bytes of a file
const file = await Deno.open("example.txt", { read: true });
const bytes = await readRange(file, { start: 0, end: 9 });
assertEquals(bytes.length, 10);

Parameters

r: Reader & Deno.Seeker
range: ByteRange

Returns

Promise<Uint8Array>