A simple JavaScript module for download file from a Blob in the Browser-side.
NPM:
npm install @perseu/browser-file-downloaderYarn:
yarn add @perseu/browser-file-downloaderimport FileDownloader from '@perseu/browser-file-downloader'
await FileDownloader.downloadFileAsPdf(blob, fileName)downloadFileAsPdf(data, fileName)
-
data: File|ArrayBuffer|Blobthe data object to be downloaded. -
fileName: ?Stringthe name of the file that will be downloaded. The file extension type should to be explicit (e.g.Download.pdf). The default value isDownload. -
returns: Promise<void>This method will download the
dataas a PDF file.
downloadFileAs(data, type, fileName)
-
data: File|ArrayBuffer|Blobthe data object to be downloaded. -
type: ?Stringthe MIME type of the file. The default value istext/plain. -
fileName: ?Stringthe name of the file that will be downloaded. The file extension type should to be explicit (e.g.Download.pdf). The default value isDownload. -
returns: Promise<void>This method will download the
dataas specified intypeparameter.
downloadFile(blob, fileName)
-
blob: Blobthe blob object to be downloaded. -
fileName: Stringthe name of the file that will be downloaded. The file extension type should to be explicit (e.g.Download.pdf). -
returns: voidThis method will download the
blobas a file. The file type should be informed on the Blob object.
base64ToArrayBuffer(base64)
-
base64: Stringthe base64 string to be converted. -
returns: ArrayBufferThis method will convert the
base64string to aArrayBufferobject.