2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-11-29 13:55:38 +00:00
|
|
|
|
2023-07-13 07:04:30 +00:00
|
|
|
import { assertEquals, assertRejects } from "../assert/mod.ts";
|
2022-11-29 13:55:38 +00:00
|
|
|
import { LimitedBytesTransformStream } from "./limited_bytes_transform_stream.ts";
|
|
|
|
|
2024-02-27 20:12:47 +00:00
|
|
|
Deno.test("LimitedBytesTransformStream", async function () {
|
2023-11-10 03:57:52 +00:00
|
|
|
const r = ReadableStream.from([
|
|
|
|
new Uint8Array([1, 2, 3]),
|
|
|
|
new Uint8Array([4, 5, 6]),
|
|
|
|
new Uint8Array([7, 8, 9]),
|
|
|
|
new Uint8Array([10, 11, 12]),
|
|
|
|
new Uint8Array([13, 14, 15]),
|
|
|
|
new Uint8Array([16, 17, 18]),
|
2023-11-10 19:00:28 +00:00
|
|
|
]).pipeThrough(new LimitedBytesTransformStream(7));
|
2022-11-29 13:55:38 +00:00
|
|
|
|
2023-11-10 19:00:28 +00:00
|
|
|
const chunks = await Array.fromAsync(r);
|
2022-11-29 13:55:38 +00:00
|
|
|
assertEquals(chunks.length, 2);
|
|
|
|
});
|
|
|
|
|
2024-02-27 20:12:47 +00:00
|
|
|
Deno.test("LimitedBytesTransformStream handles error", async function () {
|
2023-11-10 03:57:52 +00:00
|
|
|
const r = ReadableStream.from([
|
|
|
|
new Uint8Array([1, 2, 3]),
|
|
|
|
new Uint8Array([4, 5, 6]),
|
|
|
|
new Uint8Array([7, 8, 9]),
|
|
|
|
new Uint8Array([10, 11, 12]),
|
|
|
|
new Uint8Array([13, 14, 15]),
|
|
|
|
new Uint8Array([16, 17, 18]),
|
2023-11-10 19:00:28 +00:00
|
|
|
]).pipeThrough(new LimitedBytesTransformStream(7, { error: true }));
|
2022-11-29 13:55:38 +00:00
|
|
|
|
2023-11-10 19:00:28 +00:00
|
|
|
await assertRejects(async () => await Array.fromAsync(r), RangeError);
|
2022-11-29 13:55:38 +00:00
|
|
|
});
|