Removed AsyncIterableReader which can be replaced by readerFromIterable available in the std

This commit is contained in:
didier amyot committed 2023-06-13 07:43:07 -04:00
1 parent 789fb49e8b
commit f7a8d494f5
3 files changed
-111

No files matched your search

-1
View File
@@ -1,5 +1,4 @@
export function* randomNumbers(seed: number, max: number, maxResult: number|undefined = undefined) : Generator<number> {
const a = 48271;
const m = 2147483647;
-44
View File
@@ -1,44 +0,0 @@
import { readAll } from "https://deno.land/std@0.191.0/streams/read_all.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import { AsyncIterableReader } from "../src/utils.ts";
import { randomNumbers, range } from "./utils.ts";
Deno.test("AsyncIterableReader", async (t) => {
async function* miniSource(){
yield Promise.resolve(new Uint8Array([1, 2, 3]));
yield Promise.resolve(new Uint8Array([4, 5, 6, 7]));
yield Promise.resolve(new Uint8Array([8, 9]));
}
async function* largeSource(size: number, seed = 77): AsyncIterable<Uint8Array>{
let val = 0
const random = randomNumbers(seed, size > 10 ? size / 4: size);
while(val < size){
const randomValue = random.next().value;
const newVal = Math.min(val + randomValue, size);
const ret = new Uint8Array(range(val, newVal));
yield Promise.resolve(ret);
val = newVal;
}
}
await t.step('read all mini source', async () => {
const reader = new AsyncIterableReader(miniSource());
const expt = new Uint8Array([1, 2 ,3 ,4 ,5, 6,7,8,9])
assertEquals(await readAll(reader), expt);
});
await t.step('read all large source', async () => {
// let's run the test 1000 times to make sure implementation is ok.
for(const i of randomNumbers(666, 100 * 1024, 1000)){
const reader = new AsyncIterableReader(largeSource(i));
const ret = await readAll(reader);
assertEquals(ret.length, i);
}
});
});