/**
 * Manipulation des images
 */
class FileUtils {
  /**
   * Returns a blob with the given data and the image filetype
   *
   * @param data
   * @param filetype
   */
  public static newBlob(data: string, filetype: string = 'image/jpeg'): Blob {
    return new Blob([data as BlobPart], { type: filetype })
  }

  /**
   * Transforme un Blob en Base64
   * @param {Blob} blob
   */
  public static blobToBase64(blob: Blob): Promise<string> {
    return new Promise((resolve, _reject) => {
      const reader = new FileReader()
      reader.onloadend = () => resolve(reader.result as string)
      reader.readAsDataURL(blob)
    })
  }
}
export default FileUtils
