Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function stringToDataUrl(string, type='text/plain') {
// Using self.btoa is faster but fails for unicode strings.
const blob = new Blob([string], {type})
const dataUrl = await blobToDataURL(blob)
return dataUrl
}
async updateFile() {
const { doc, attachmentId } = this.props
let blob
try {
blob = await db.getAttachment(doc._id, attachmentId)
} catch (err) {}
const dataUrl = blob ? await blobToDataURL(blob) : undefined
if (this._isMounted) {
this.setState({ dataUrl })
}
}