From 50a47be190f7a8674652b0b52e19c5b5efec4515 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 19 Aug 2018 13:37:19 +0200 Subject: [PATCH] [api-minor] Remove the obsolete `createBlob` helper function At this point in time, all supported browsers have native support for `Blob`; please see https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#Browser_compatibility. Furthermore, note how the helper function was throwing an error if `Blob` isn't available anyway. --- src/pdf.js | 1 - src/shared/util.js | 10 +--------- web/app.js | 10 +++++----- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/pdf.js b/src/pdf.js index b1a1a4cdbd3a7..7315450614222 100644 --- a/src/pdf.js +++ b/src/pdf.js @@ -101,7 +101,6 @@ exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl; exports.createObjectURL = pdfjsSharedUtil.createObjectURL; exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters; exports.shadow = pdfjsSharedUtil.shadow; -exports.createBlob = pdfjsSharedUtil.createBlob; exports.Util = pdfjsSharedUtil.Util; exports.ReadableStream = pdfjsSharedUtil.ReadableStream; exports.URL = pdfjsSharedUtil.URL; diff --git a/src/shared/util.js b/src/shared/util.js index 642bacf9e3457..80115a1021533 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -969,13 +969,6 @@ function createPromiseCapability() { return capability; } -var createBlob = function createBlob(data, contentType) { - if (typeof Blob !== 'undefined') { - return new Blob([data], { type: contentType, }); - } - throw new Error('The "Blob" constructor is not supported.'); -}; - var createObjectURL = (function createObjectURLClosure() { // Blob/createObjectURL is not available, falling back to data schema. var digits = @@ -983,7 +976,7 @@ var createObjectURL = (function createObjectURLClosure() { return function createObjectURL(data, contentType, forceDataSchema = false) { if (!forceDataSchema && URL.createObjectURL) { - var blob = createBlob(data, contentType); + const blob = new Blob([data], { type: contentType, }); return URL.createObjectURL(blob); } @@ -1033,7 +1026,6 @@ export { arraysToBytes, assert, bytesToString, - createBlob, createPromiseCapability, createObjectURL, deprecated, diff --git a/web/app.js b/web/app.js index 933d9eba72998..f3d0635007775 100644 --- a/web/app.js +++ b/web/app.js @@ -21,10 +21,10 @@ import { TextLayerMode } from './ui_utils'; import { - build, createBlob, createObjectURL, getDocument, getFilenameFromUrl, - GlobalWorkerOptions, InvalidPDFException, LinkTarget, loadScript, - MissingPDFException, OPS, PDFWorker, shadow, UnexpectedResponseException, - UNSUPPORTED_FEATURES, URL, version + build, createObjectURL, getDocument, getFilenameFromUrl, GlobalWorkerOptions, + InvalidPDFException, LinkTarget, loadScript, MissingPDFException, OPS, + PDFWorker, shadow, UnexpectedResponseException, UNSUPPORTED_FEATURES, URL, + version } from 'pdfjs-lib'; import { CursorTool, PDFCursorTools } from './pdf_cursor_tools'; import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue'; @@ -748,7 +748,7 @@ let PDFViewerApplication = { } this.pdfDocument.getData().then(function(data) { - let blob = createBlob(data, 'application/pdf'); + const blob = new Blob([data], { type: 'application/pdf', }); downloadManager.download(blob, url, filename); }).catch(downloadByUrl); // Error occurred, try downloading with the URL. },