package/package.json000644 000765 000024 0000002304 13127261150013012 0ustar00000000 000000 { "name": "remove-bom-stream", "version": "1.2.0", "description": "Remove a UTF8 BOM at the start of the stream.", "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ "Blaine Bublitz " ], "repository": "gulpjs/remove-bom-stream", "license": "MIT", "engines": { "node": ">= 0.10" }, "main": "index.js", "files": [ "LICENSE", "index.js" ], "scripts": { "lint": "eslint index.js test/ && jscs index.js test/", "pretest": "npm run lint", "test": "mocha --async-only", "cover": "istanbul cover _mocha", "coveralls": "npm run cover && istanbul-coveralls" }, "dependencies": { "safe-buffer": "^5.1.0", "remove-bom-buffer": "^3.0.0", "through2": "^2.0.3" }, "devDependencies": { "buffer-equal": "^1.0.0", "eslint": "^1.10.3", "eslint-config-gulp": "^2.0.0", "expect": "^1.20.2", "istanbul": "^0.4.3", "istanbul-coveralls": "^1.0.3", "jscs": "^2.4.0", "jscs-preset-gulp": "^1.0.0", "mississippi": "^1.3.0", "mocha": "^3.2.0", "stream-chunker": "^1.2.8" }, "keywords": [ "bom", "remove", "utf8", "streaming", "stream" ] } package/README.md000644 000765 000024 0000003445 13121063576012020 0ustar00000000 000000

# remove-bom-stream [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] Remove a UTF8 BOM at the start of the stream. ## Usage ```js var fs = require('fs'); var concat = require('concat-stream'); var removeBOM = require('remove-bom-stream'); fs.createReadStream('utf8-file-with-bom.txt') .pipe(removeBOM()) .pipe(concat(function(result) { // result won't have a BOM })); ``` ## API ### `removeBOM()` Returns a `through2` stream that will remove a BOM, given the data is a UTF8 Buffer with a BOM at the beginning. If the data is not UTF8 or does not have a BOM, the data is not changed and this becomes a normal passthrough stream. ## License MIT [downloads-image]: http://img.shields.io/npm/dm/remove-bom-stream.svg [npm-url]: https://npmjs.com/package/remove-bom-stream [npm-image]: http://img.shields.io/npm/v/remove-bom-stream.svg [travis-url]: https://travis-ci.org/gulpjs/remove-bom-stream [travis-image]: http://img.shields.io/travis/gulpjs/remove-bom-stream.svg?label=travis-ci [appveyor-url]: https://ci.appveyor.com/project/gulpjs/remove-bom-stream [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/remove-bom-stream.svg?label=appveyor [coveralls-url]: https://coveralls.io/r/gulpjs/remove-bom-stream [coveralls-image]: http://img.shields.io/coveralls/gulpjs/remove-bom-stream/master.svg [gitter-url]: https://gitter.im/gulpjs/gulp [gitter-image]: https://badges.gitter.im/gulpjs/gulp.png package/LICENSE000644 000765 000024 0000002214 13121051331011521 0ustar00000000 000000 The MIT License (MIT) Copyright (c) 2017 Blaine Bublitz , Eric Schoffstall and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/index.js000644 000765 000024 0000001760 13121072540012173 0ustar00000000 000000 'use strict'; var through = require('through2'); var removeBom = require('remove-bom-buffer'); var SafeBuffer = require('safe-buffer').Buffer; function removeBomStream() { var completed = false; var buffer = SafeBuffer.alloc(0); return through(onChunk, onFlush); function removeAndCleanup(data) { completed = true; buffer = null; return removeBom(data); } function onChunk(data, enc, cb) { if (completed) { return cb(null, data); } if (data.length >= 7) { return cb(null, removeAndCleanup(data)); } var bufferLength = buffer.length; var chunkLength = data.length; var totalLength = bufferLength + chunkLength; buffer = SafeBuffer.concat([buffer, data], totalLength); if (totalLength >= 7) { return cb(null, removeAndCleanup(buffer)); } cb(); } function onFlush(cb) { if (completed || !buffer) { return cb(); } cb(null, removeAndCleanup(buffer)); } } module.exports = removeBomStream;