vue electron read file

Solutions on MaxInterview for vue electron read file by the best coders in the world

showing results for - "vue electron read file"
Leela
26 Aug 2020
1import fs from 'fs'
2import readline from 'readline'
3import iconv from 'iconv-lite'
4
5ipcMain.on('readfile', async (event, arg) => {
6    await readLines()
7    event.sender.send('readfile-reply', 'complete')
8})
9
10function readLines() {
11    return new Promise((resolve, reject) => {
12        stream = fs.createReadStream(filePath).pipe(iconv.decodeStream('shift-jis'))
13        let reader = readline.createInterface(stream, {})
14        reader
15            .on('line', line => {
16                insertLine(line)
17            })
18            .on('close', () => {
19                resolve() // "Resolve" in the close event.
20            })
21            .on('error', function(err) {
22                reject(err)
23            })
24    })
25}
26