Added a very complicated AsyncIterableReader class.
The class was already implemented in "https://deno.land/std@0.144.0/streams/conversion.ts". So, I litterally lost 1 day of work! I hate myself.
This commit is contained in:
1 parent
17a1b4bed3
commit
0d627c9051
125 files changed
+26943
-83
No files matched your search
@@ -23,7 +23,7 @@ Deno.test("DenoKVBlobService happy path", async (t) => {
|
||||
|
||||
await t.step("read write small text", async () => {
|
||||
const size = await bs.persistBlob("0002", toUint8Array("hello world"));
|
||||
const body = await bs.getBlob("0002");
|
||||
const body = await bs.readAllBlob("0002");
|
||||
assertEquals(body, toUint8Array("hello world"));
|
||||
assertEquals(await bs.getNumberOfBlobs("0002"), 1);
|
||||
assertEquals(size, "hello world".length);
|
||||
@@ -32,7 +32,7 @@ Deno.test("DenoKVBlobService happy path", async (t) => {
|
||||
await t.step("read write large text", async () => {
|
||||
const largeText = toUint8Array(generateLargeText(33, 100));
|
||||
const size = await bs.persistBlob("0001", largeText);
|
||||
const body = await bs.getBlob("0001");
|
||||
const body = await bs.readAllBlob("0001");
|
||||
assertEquals(body, largeText);
|
||||
assertEquals(await bs.getNumberOfBlobs("0001"), 21);
|
||||
assertEquals(size, largeText.length);
|
||||
|
||||
+6
-1
@@ -1,12 +1,17 @@
|
||||
|
||||
|
||||
export function* randomNumbers(seed: number, max: number) : Generator<number> {
|
||||
export function* randomNumbers(seed: number, max: number, maxResult: number|undefined = undefined) : Generator<number> {
|
||||
const a = 48271;
|
||||
const m = 2147483647;
|
||||
max = Math.floor(max);
|
||||
let i = 0;
|
||||
while (true) {
|
||||
seed = (a * seed) % m;
|
||||
yield seed % max;
|
||||
i ++;
|
||||
if(maxResult !== undefined && i >= maxResult){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
-57
@@ -12,72 +12,33 @@ Deno.test("AsyncIterableReader", async (t) => {
|
||||
yield Promise.resolve(new Uint8Array([8, 9]));
|
||||
}
|
||||
|
||||
async function* largeSource(size: number): AsyncIterable<Uint8Array>{
|
||||
async function* largeSource(size: number, seed = 77): AsyncIterable<Uint8Array>{
|
||||
|
||||
let val = 0
|
||||
const random = randomNumbers(77, size / 4);
|
||||
const random = randomNumbers(seed, size > 10 ? size / 4: size);
|
||||
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)));
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
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 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 () => {
|
||||
// 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);
|
||||
// }
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
// <<<<<<<<<<<<<<<<< 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