std/streams/fixed_chunk_stream_test.ts
Doctor 77345498a2
feat(streams/unstable): FixedChunkStream (#4995)
* feat(streams): new ResizeStreams(size)

* chore(streams): Renamed ResizeStream to FixedChunkStream

* Update streams/fixed_chunk_stream_test.ts

* update

* tweaks

* tweak test

* fix(streams): chunks getting lost if size was equally divisible by `size`

* work

* work

---------

Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
2024-08-07 10:34:54 +02:00

19 lines
629 B
TypeScript

// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assert, assertLessOrEqual } from "@std/assert";
import { FixedChunkStream } from "./fixed_chunk_stream.ts";
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);
});