Started to implement server
This commit is contained in:
1 parent
1f2ea8b7e5
commit
17a1b4bed3
177 files changed
+29894
-74
No files matched your search
@@ -0,0 +1,83 @@
|
||||
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): AsyncIterable<Uint8Array>{
|
||||
let val = 0
|
||||
const random = randomNumbers(77, size / 4);
|
||||
while(val < size){
|
||||
const newVal = Math.min(val + random.next().value, size);
|
||||
// console.log(range(val, newVal));
|
||||
console.log("<<<<<<<<<<<<<<<<< " + newVal + "/" + size + " ( " + (newVal - val) )
|
||||
yield Promise.resolve(new Uint8Array(range(val, newVal)));
|
||||
|
||||
val = newVal;
|
||||
|
||||
|
||||
}
|
||||
yield Promise.resolve(new Uint8Array([9]));
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>> ");
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>> ");
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>> ");
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>> ");
|
||||
}
|
||||
|
||||
// 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('largeSource', async () =>{
|
||||
const source = largeSource(32920);
|
||||
for await(const _piece of source){
|
||||
//
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
await t.step('read all large source', async () => {
|
||||
// for(let i = 101; i < (32 * 1024 * 50 + 101); i += 1){
|
||||
let n = 32 * 1024 * 50 + 101 // 32920; //32 * 1024 * 2;
|
||||
n = 32919
|
||||
const reader = new AsyncIterableReader(largeSource(n));
|
||||
const ret = await readAll(reader);
|
||||
assertEquals(ret.length, n);
|
||||
// }
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<< 5137/32920
|
||||
// <<<<<<<<<<<<<<<<< 11593/32920
|
||||
// <<<<<<<<<<<<<<<<< 12563/32920
|
||||
// <<<<<<<<<<<<<<<<< 15976/32920
|
||||
// <<<<<<<<<<<<<<<<< 19155/32920
|
||||
// <<<<<<<<<<<<<<<<< 20038/32920
|
||||
// <<<<<<<<<<<<<<<<< 26452/32920
|
||||
// <<<<<<<<<<<<<<<<< 31797/32920
|
||||
// <<<<<<<<<<<<<<<<< 31994/32920
|
||||
// <<<<<<<<<<<<<<<<< 32912/32920
|
||||
// <<<<<<<<<<<<<<<<< 32920/32920
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<< 5137/32920
|
||||
// <<<<<<<<<<<<<<<<< 11593/32920
|
||||
// <<<<<<<<<<<<<<<<< 12563/32920
|
||||
// <<<<<<<<<<<<<<<<< 15976/32920
|
||||
// <<<<<<<<<<<<<<<<< 19155/32920
|
||||
// <<<<<<<<<<<<<<<<< 20038/32920
|
||||
// <<<<<<<<<<<<<<<<< 26452/32920
|
||||
// <<<<<<<<<<<<<<<<< 31797/32920
|
||||
// <<<<<<<<<<<<<<<<< 31994/32920
|
||||
Reference in new issue
Block a user