musescore-downloader/src/mscz.ts

25 lines
601 B
TypeScript
Raw Normal View History

2020-05-18 22:44:45 +00:00
import { saveAs } from './utils'
import scoreinfo from './scoreinfo'
let msczBufferP: Promise<ArrayBuffer> | undefined
export const fetchMscz = async (): Promise<ArrayBuffer> => {
if (!msczBufferP) {
const url = scoreinfo.msczUrl
msczBufferP = (async (): Promise<ArrayBuffer> => {
const r = await fetch(url)
2020-05-18 22:44:45 +00:00
const data = await r.arrayBuffer()
return data
})()
}
return msczBufferP
}
export const downloadMscz = async (): Promise<void> => {
const data = new Blob([await fetchMscz()])
const filename = scoreinfo.fileName
saveAs(data, `${filename}.mscz`)
}