async function CustomOpen(url)
{
pdfui.close();
progressComponent.show(document.body);
progressComponent.updateProgress(0, PDFViewCtrl.constants.PROGRESS_STATUS.PROGRESSING);
// 1. 发起请求并获取流读取器
var response = await fetch(url);
const reader = response.body.getReader();
// 2. 获取总长度
const contentLength = +response.headers.get('Content-Length');
let receivedLength = 0;
let chunks = [];
// 3. 读取数据块
while(true) {
const {done, value} = await reader.read();
if (done) break;
chunks.push(value);
receivedLength += value.length;
const percent = Math.round((receivedLength / contentLength) * 100);
progressComponent.updateProgress(percent, PDFViewCtrl.constants.PROGRESS_STATUS.PROGRESSING);
}
// 4. 合并数据块
const chunksAll = new Uint8Array(receivedLength);
let position = 0;
for(let chunk of chunks) {
chunksAll.set(chunk, position);
position += chunk.length;
}
pdfui.openPDFByFile(chunksAll)
}