Package Exports
- write-file-utf8
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (write-file-utf8) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
write-file-utf8
shortcut to fs.writeFile
Installation | API | Usage | See also | License
Installation
With npm do
npm install write-file-utf8
API
writeFileUtf8(filePath, content[, callback])
- @param
{String}
filePath - @param
{String}
content - @param
{Function}
[callback] defaults to a trivialif (err) throw err
writeFileUtf8.error
An object exposing the following error messages:
- contentIsNotString
For example, try the following snippet
var write = require('write-file-utf8')
try {
var buffer = new Buffer('a')
write('/tmp/foo', buffer)
} catch (err) {
if (err.message === write.error.contentIsNotString) {
console.log('Hey, are buffers utf-8 encoded?')
}
}
Usage
var write = require('write-file-utf8')
var filePath = '/tmp/foo'
var content = 'bar'
write(filePath, content)
Actually is the same as
var fs = require('fs')
var filePath = '/tmp/foo'
var content = 'bar'
function throwError (err) {
if (err) {
throw err
}
}
fs.writeFile(filePath, content, 'utf8', throwError)
It accepts also an optional callback, for example
write(filePath, content, (err) => {
if (err) throw err
console.log(`File saved: ${filePath}`)
})