1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-07 02:28:54 +08:00

add test for exportToFile

This commit is contained in:
lana-k
2021-01-21 12:49:10 +01:00
parent 1be139d327
commit 6886b7903f
4 changed files with 72 additions and 2 deletions

17
src/fileUtils.js Normal file
View File

@@ -0,0 +1,17 @@
export default {
exportToFile (str, fileName, type = 'octet/stream') {
// Create downloader
const downloader = document.createElement('a')
const blob = new Blob([str], { type })
const url = URL.createObjectURL(blob)
downloader.href = url
downloader.download = fileName
// Trigger click
downloader.click()
// Clean up
URL.revokeObjectURL(url)
downloader.remove()
}
}