Browse Source

Fix performance degradation

pull/46/head
coomdev 2 years ago
parent
commit
f768b23db3
  1. 9
      src/main.ts

9
src/main.ts

@ -40,13 +40,14 @@ appState.subscribe(v => {
});
// most pngs are encoded with 65k idat chunks
async function* streamRemote(url: string, chunkSize = 16 * 1024, fetchRestOnNonCanceled = true) {
async function* streamRemote(url: string, chunkSize = 72 * 1024, fetchRestOnNonCanceled = true) {
const headers = await GM_head(url);
const h = headerStringToObject(headers);
const size = +h['content-length'];
let ptr = 0;
let fetchSize = chunkSize;
while (ptr != size) {
console.log('doing a fetch of ', url, ptr, ptr + fetchSize - 1);
const res = await GM_fetch(url, { headers: { range: `bytes=${ptr}-${ptr + fetchSize - 1}` } }) as any as Tampermonkey.Response<any>;
const obj = headerStringToObject(res.responseHeaders);
if (!('content-length' in obj)) {
@ -58,6 +59,7 @@ async function* streamRemote(url: string, chunkSize = 16 * 1024, fetchRestOnNonC
fetchSize = size;
const val = Buffer.from(await (res as any).arrayBuffer());
const e = (yield val) as boolean;
console.log('yeieledd, a', e);
if (e) {
break;
}
@ -109,10 +111,11 @@ const processImage = async (src: string, fn: string, hex: string): Promise<([Emb
if (!done)
cumul = Buffer.concat([cumul, value!]);
found = await proc.has_embed(cumul);
console.log(`on ${src} ${found}...`);
} while (found !== false && !chunk.done);
await iter.next(false);
await iter.next(true);
if (found === false) {
//console.log(`Gave up on ${src} after downloading ${cumul.byteLength} bytes...`);
console.log(`Gave up on ${src} after downloading ${cumul.byteLength} bytes...`);
return;
}
return [await proc.extract(cumul), false] as [EmbeddedFile, boolean];

Loading…
Cancel
Save