Skip to content

Commit

Permalink
Merge pull request #18216 from Snuffleupagus/download-data
Browse files Browse the repository at this point in the history
Change `DownloadManager.download` to use Uint8Array-data
  • Loading branch information
timvandermeij authored Jun 7, 2024
2 parents 6a71f69 + 66e189c commit 593ce96
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
10 changes: 3 additions & 7 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1083,13 +1083,11 @@ const PDFViewerApplication = {
this._ensureDownloadComplete();

const data = await this.pdfDocument.getData();
const blob = new Blob([data], { type: "application/pdf" });

await this.downloadManager.download(blob, url, filename, options);
this.downloadManager.download(data, url, filename, options);
} catch {
// When the PDF document isn't ready, or the PDF file is still
// downloading, simply download using the URL.
await this.downloadManager.downloadUrl(url, filename, options);
this.downloadManager.downloadUrl(url, filename, options);
}
},

Expand All @@ -1106,9 +1104,7 @@ const PDFViewerApplication = {
this._ensureDownloadComplete();

const data = await this.pdfDocument.saveDocument();
const blob = new Blob([data], { type: "application/pdf" });

await this.downloadManager.download(blob, url, filename, options);
this.downloadManager.download(data, url, filename, options);
} catch (reason) {
// When the PDF document isn't ready, or the PDF file is still
// downloading, simply fallback to a "regular" download.
Expand Down
6 changes: 4 additions & 2 deletions web/download_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ class DownloadManager {
return false;
}

download(blob, url, filename, _options) {
const blobUrl = URL.createObjectURL(blob);
download(data, url, filename, _options) {
const blobUrl = URL.createObjectURL(
new Blob([data], { type: "application/pdf" })
);
download(blobUrl, filename);
}
}
Expand Down
6 changes: 4 additions & 2 deletions web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ class DownloadManager {
return false;
}

download(blob, url, filename, options = {}) {
const blobUrl = URL.createObjectURL(blob);
download(data, url, filename, options = {}) {
const blobUrl = URL.createObjectURL(
new Blob([data], { type: "application/pdf" })
);

FirefoxCom.request("download", {
blobUrl,
Expand Down
4 changes: 2 additions & 2 deletions web/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ class IDownloadManager {
openOrDownloadData(data, filename, dest = null) {}

/**
* @param {Blob} blob
* @param {Uint8Array} data
* @param {string} url
* @param {string} filename
* @param {Object} [options]
*/
download(blob, url, filename, options) {}
download(data, url, filename, options) {}
}

/**
Expand Down

0 comments on commit 593ce96

Please sign in to comment.