1 |
|
2 |
|
3 | const fse = require('fs-extra')
|
4 | const log = require('./log')
|
5 |
|
6 | /**
|
7 | * Saves a file to disk.
|
8 | * @public
|
9 | * @param {String} filePath - Absolute path where the file should be saved to.
|
10 | * @param {String|Buffer} data - Content of file.
|
11 | * @param {Object} opts - Additional optional options.
|
12 | * @param {Function} next - The callback that handles the response. Receives the following properties: err.
|
13 | */
|
14 | module.exports = function(filePath, data, opts, next) {
|
15 |
|
16 | if (opts.verbose===true) log(`{cyan:Saving file: {grey:${ filePath }`)
|
17 |
|
18 | fse.outputFile(filePath, data, (err) => {
|
19 |
|
20 | if (err!=null) return next(err)
|
21 |
|
22 | if (opts.verbose===true) log(`{cyan:Saved file: {grey:${ filePath }`)
|
23 |
|
24 | next()
|
25 |
|
26 | })
|
27 |
|
28 | } |
\ | No newline at end of file |