Created
November 10, 2016 08:39
-
-
Save wangpin34/cd23bc9d7c145983cd12bf300a9c4e64 to your computer and use it in GitHub Desktop.
Nodejs file util
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const Promise = require('bluebird'); | |
const fs = Promise.promisifyAll(require('fs')); | |
const path = require('path'); | |
/* | |
* Bom headers are 3 Bytes binary | |
*/ | |
const removeBom = filePath => { | |
return fs.readFileAsync(filePath).then(buff => { | |
if(buff[0].toString(16).toLowerCase() === 'ef' && buff[1].toString(16).toLowerCase() === 'bb' && buff[2].toString(16).toLowerCase() === 'bf'){ | |
console.log('%s has bom headers', filePath) | |
buff = buff.slice(3) | |
return fs.writeFileAsync(filePath, buff.toString(), 'utf8') | |
} | |
return | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment