Skip to content

Commit

Permalink
Merge 5e63630 into bc47af6
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Mar 26, 2022
2 parents bc47af6 + 5e63630 commit f859c7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion index.js
@@ -1,7 +1,7 @@
'use strict';

var through = require('through2');
var removeBom = require('remove-bom-buffer');
var isUTF8 = require('is-utf8');

function removeBomStream() {
var completed = false;
Expand Down Expand Up @@ -47,4 +47,19 @@ function removeBomStream() {
}
}

function removeBom(buf) {
if (Buffer.isBuffer(buf) && matchBOM(buf) && maybeUTF8(buf)) {
return buf.slice(3);
}
return buf;
}

function matchBOM(buf) {
return buf[0] === 0xEF && buf[1] === 0xBB && buf[2] === 0xBF;
}

function maybeUTF8(buf) {
return isUTF8(buf.slice(3, 7));
}

module.exports = removeBomStream;
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -22,7 +22,7 @@
"test": "nyc mocha --async-only"
},
"dependencies": {
"remove-bom-buffer": "^3.0.0",
"is-utf8": "^0.2.1",
"through2": "^4.0.2"
},
"devDependencies": {
Expand Down

0 comments on commit f859c7a

Please sign in to comment.