All files / platform/core/src/utils downloadBlob.ts

85.71% Statements 12/14
50% Branches 1/2
75% Functions 3/4
85.71% Lines 12/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37        1x 1x 1x                                 1x 1x 1x 1x 1x 1x 1x       1x 1x    
/**
 * Converts a blob to a URL and downloads immediate
 */
export function downloadBlob(content, options?) {
  const url = URL.createObjectURL(content);
  downloadUrl(url, options);
  URL.revokeObjectURL(url);
}
 
/**
 * Trigger file download from an array buffer
 * @param buffer
 * @param filename
 */
export function downloadDicom(buffer: ArrayBuffer, options) {
  const blob = new Blob([buffer], { type: 'application/dicom' });
  downloadBlob(blob, options);
}
 
/**
 * Downloads a URL
 */
export function downloadUrl(url, options?) {
  const link = document.createElement('a');
  link.setAttribute('href', url);
  const filename = options?.filename || 'file.dcm';
  link.setAttribute('download', filename);
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}
 
export function downloadCsv(csvString: string, options?) {
  const blob = new Blob([csvString], { type: 'text/csv;charset=utf-8;' });
  downloadBlob(blob, options);
}