io/io-utils/convertToBlob.js

  1. const makeBlob = require('./makeBlob')
  2. const Blob = makeBlob()
  3. /**
  4. * Convert the given input into a BLOB of data for export.
  5. * @param {Object} input - input object to convert
  6. * @param {Array} input.data - array of data to be inserted into the blob, either String or ArrayBuffer
  7. * @param {String} input.mimeType - mime type of the data to be inserted
  8. * @return {Blob} a new Blob
  9. * @alias module:io/utils.convertToBlob
  10. * @example
  11. * const blob1 = convertToBlob({ data: ['test'], mimeType: 'text/plain' })
  12. * const blob2 = convertToBlob({ data: [Int32Array.from('12345').buffer], mimeType: 'application/mine' })
  13. */
  14. const convertToBlob = (input) => {
  15. const { data, mimeType } = input
  16. const blob = new Blob(data, { type: mimeType })
  17. return blob
  18. }
  19. module.exports = convertToBlob