Commit 996e96b0 authored by Skye Yu's avatar Skye Yu

test: continue decode

parent 691becf6
...@@ -31,7 +31,7 @@ declare class JensenType { ...@@ -31,7 +31,7 @@ declare class JensenType {
fileName: string, fileName: string,
length: number, length: number,
on?: (msg: Uint8Array | 'fail') => void, on?: (msg: Uint8Array | 'fail') => void,
onprogress?: (size: number, msg: Uint8Array | null) => void onprogress?: (size: number) => void
) => void; ) => void;
getFileBlock: ( getFileBlock: (
fileName: string, fileName: string,
......
...@@ -314,15 +314,20 @@ function Jensen(log) { ...@@ -314,15 +314,20 @@ function Jensen(log) {
// 做一个回调,怎么样找到它呢? // 做一个回调,怎么样找到它呢?
blocks.push(result.data); blocks.push(result.data);
tryReceive(); tryReceive();
if (self.decodeTimeout) clearTimeout(self.decodeTimeout); if (self.onreceive) {
self.decodeTimeout = setTimeout(function () { const arr = [];
tryDecode(); arr.push(result.data);
}, self.timewait); tryDecode(arr);
if (self.onreceive)
try { try {
self.onreceive(totalBytes, continueDecode(result.data)); self.onreceive(totalBytes);
} catch (e) { } catch (e) {
} }
} else {
if (self.decodeTimeout) clearTimeout(self.decodeTimeout);
self.decodeTimeout = setTimeout(function () {
tryDecode(blocks);
}, self.timewait);
}
}; };
// 持续解码 // 持续解码
...@@ -342,7 +347,7 @@ function Jensen(log) { ...@@ -342,7 +347,7 @@ function Jensen(log) {
return result && msg.id === TRANSFER_FILE ? msg.body : null; return result && msg.id === TRANSFER_FILE ? msg.body : null;
} }
const tryDecode = function () { const tryDecode = function (blocks) {
// 一个容器,比单独任意一个小包要大一点儿,好像还差一点儿 // 一个容器,比单独任意一个小包要大一点儿,好像还差一点儿
let stime = new Date(); let stime = new Date();
let buff = new ArrayBuffer(RECV_BUFF_SIZE * 2); let buff = new ArrayBuffer(RECV_BUFF_SIZE * 2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment