fileUtils.ts 790 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Manipulation des images
  3. */
  4. class FileUtils {
  5. // Private constructor to prevent instantiation
  6. private constructor() {
  7. // This utility class is not meant to be instantiated
  8. }
  9. /**
  10. * Returns a blob with the given data and the file's type
  11. *
  12. * @param data
  13. * @param filetype
  14. */
  15. public static newBlob(data: BlobPart, filetype: string = 'image/jpeg'): Blob {
  16. return new Blob([data], { type: filetype })
  17. }
  18. /**
  19. * Transforme un Blob en Base64
  20. * @param {Blob} blob
  21. */
  22. public static blobToBase64(blob: Blob): Promise<string> {
  23. return new Promise((resolve, _reject) => {
  24. const reader = new FileReader()
  25. reader.onloadend = () => resolve(reader.result as string)
  26. reader.readAsDataURL(blob)
  27. })
  28. }
  29. }
  30. export default FileUtils