Ensure Hunspell dictionary before downloading (#1675)

This commit is contained in:
Felix Häusler 2019-11-11 17:37:00 +01:00 committed by GitHub
parent 1a3020a5b1
commit a3428b5151
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,8 @@ export const downloadHunspellDictionary = async lang => {
responseType: 'stream' responseType: 'stream'
}) })
await fs.ensureDir(dictionaryPath)
const dstFile = path.join(dictionaryPath, `${lang}.bdic`) const dstFile = path.join(dictionaryPath, `${lang}.bdic`)
const tmpFile = `${dstFile}.tmp` const tmpFile = `${dstFile}.tmp`
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -31,11 +33,13 @@ export const downloadHunspellDictionary = async lang => {
outStream.once('error', reject) outStream.once('error', reject)
outStream.once('finish', async () => { outStream.once('finish', async () => {
if (totalLength < 8 * 1024) { if (totalLength < 8 * 1024) {
throw new Error('Dictionary is most likely bogus.') reject(new Error('Dictionary is most likely bogus.'))
return
} }
await fs.move(tmpFile, dstFile, { overwrite: true }) fs.move(tmpFile, dstFile, { overwrite: true })
resolve() .then(resolve)
.catch(reject)
}) })
}) })
} }