2024-08-07 08:34:54 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
import { assert, assertLessOrEqual } from "@std/assert";
|
2024-09-12 04:50:22 +00:00
|
|
|
import { FixedChunkStream } from "./unstable_fixed_chunk_stream.ts";
|
2024-08-07 08:34:54 +00:00
|
|
|
|
|
|
|
Deno.test("FixedChunkStream", async () => {
|
|
|
|
const size = 512;
|
|
|
|
|
|
|
|
const readable = ReadableStream.from(function* () {
|
|
|
|
for (let i = 0; i < 100; ++i) {
|
|
|
|
yield new Uint8Array(Math.random() * 1000);
|
|
|
|
}
|
|
|
|
}()).pipeThrough(new FixedChunkStream(size));
|
|
|
|
const result = await Array.fromAsync(readable);
|
|
|
|
|
|
|
|
assert(result.slice(0, -1).every((chunk) => chunk.length === size));
|
|
|
|
assertLessOrEqual(result.at(-1)!.length, size);
|
|
|
|
});
|