1 | import { createWriteStream } from 'fs'
|
2 | import erotic from 'erotic'
|
3 |
|
4 | /**
|
5 | * Write a file to the filesystem.
|
6 | * @param {string} path The path of the file to write.
|
7 | * @param {string|Buffer} data The data to write.
|
8 | */
|
9 | export default async function write(path, data) {
|
10 | if (!path) throw new Error('No path is given.')
|
11 | const er = erotic(true)
|
12 | const ws = createWriteStream(path)
|
13 | await new Promise((r, j) => {
|
14 | ws
|
15 | .on('error', (e) => {
|
16 | const err = er(e)
|
17 | j(err)
|
18 | })
|
19 | .on('close', r)
|
20 | .end(data)
|
21 | })
|
22 | } |
\ | No newline at end of file |