Skip to content

Commit 9b8467f

Browse files
committed
refactor: 移除 createObjectURL 方法精简代码逻辑
1 parent 0986dc3 commit 9b8467f

1 file changed

Lines changed: 1 addition & 23 deletions

File tree

src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,12 @@ export async function setData(id, data) {
4747
return;
4848
}
4949

50-
const objectUrl = createObjectURLFromByte(data);
51-
pdf.objectUrl = objectUrl;
52-
5350
const { options } = pdf;
5451
options.url = objectUrl;
5552
options.data = null;
5653
await loadPdf(pdf);
5754
}
5855

59-
const createObjectURLFromBase64 = base64Data => {
60-
const binaryString = atob(base64Data);
61-
const bytes = new Uint8Array(binaryString.length);
62-
for (let i = 0; i < binaryString.length; i++) {
63-
bytes[i] = binaryString.charCodeAt(i);
64-
}
65-
66-
const blob = new Blob([bytes], { type: 'application/pdf' });
67-
return URL.createObjectURL(blob);
68-
}
69-
70-
const createObjectURLFromByte = bytes => {
71-
const blob = new Blob([bytes], { type: 'application/pdf' });
72-
return URL.createObjectURL(blob);
73-
}
74-
7556
export function setScaleValue(id, value) {
7657
const { pdfViewer } = Data.get(id);
7758
if (pdfViewer) {
@@ -182,10 +163,7 @@ const loadPdf = async pdf => {
182163
}
183164

184165
const disposePdf = pdf => {
185-
const { el, observer, loadingTask, objectUrl } = pdf;
186-
if (objectUrl) {
187-
URL.revokeObjectURL(objectUrl);
188-
}
166+
const { el, observer, loadingTask } = pdf;
189167

190168
if (observer) {
191169
observer.disconnect();

0 commit comments

Comments
 (0)