deno.land / std@0.173.0 / streams / limited_bytes_transform_stream_test.ts

limited_bytes_transform_stream_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertRejects } from "../testing/asserts.ts";import { LimitedBytesTransformStream } from "./limited_bytes_transform_stream.ts";
Deno.test("[streams] LimitedBytesTransformStream", async function () { const r = new ReadableStream({ start(controller) { controller.enqueue(new Uint8Array([1, 2, 3])); controller.enqueue(new Uint8Array([4, 5, 6])); controller.enqueue(new Uint8Array([7, 8, 9])); controller.enqueue(new Uint8Array([10, 11, 12])); controller.enqueue(new Uint8Array([13, 14, 15])); controller.enqueue(new Uint8Array([16, 17, 18])); controller.close(); }, });
const chunks = []; for await (const chunk of r.pipeThrough(new LimitedBytesTransformStream(7))) { chunks.push(chunk); } assertEquals(chunks.length, 2);});
Deno.test("[streams] LimitedBytesTransformStream error", async function () { const r = new ReadableStream({ start(controller) { controller.enqueue(new Uint8Array([1, 2, 3])); controller.enqueue(new Uint8Array([4, 5, 6])); controller.enqueue(new Uint8Array([7, 8, 9])); controller.enqueue(new Uint8Array([10, 11, 12])); controller.enqueue(new Uint8Array([13, 14, 15])); controller.enqueue(new Uint8Array([16, 17, 18])); controller.close(); }, });
await assertRejects(async () => { for await ( const _chunk of r.pipeThrough( new LimitedBytesTransformStream(7, { error: true }), ) ) { // needed to read } }, RangeError);});
std

Version Info

Tagged at
a year ago