Last change
on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | var BOMChar = '\uFEFF';
|
---|
| 4 |
|
---|
| 5 | exports.PrependBOM = PrependBOMWrapper
|
---|
| 6 | function PrependBOMWrapper(encoder, options) {
|
---|
| 7 | this.encoder = encoder;
|
---|
| 8 | this.addBOM = true;
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | PrependBOMWrapper.prototype.write = function(str) {
|
---|
| 12 | if (this.addBOM) {
|
---|
| 13 | str = BOMChar + str;
|
---|
| 14 | this.addBOM = false;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | return this.encoder.write(str);
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | PrependBOMWrapper.prototype.end = function() {
|
---|
| 21 | return this.encoder.end();
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | //------------------------------------------------------------------------------
|
---|
| 26 |
|
---|
| 27 | exports.StripBOM = StripBOMWrapper;
|
---|
| 28 | function StripBOMWrapper(decoder, options) {
|
---|
| 29 | this.decoder = decoder;
|
---|
| 30 | this.pass = false;
|
---|
| 31 | this.options = options || {};
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | StripBOMWrapper.prototype.write = function(buf) {
|
---|
| 35 | var res = this.decoder.write(buf);
|
---|
| 36 | if (this.pass || !res)
|
---|
| 37 | return res;
|
---|
| 38 |
|
---|
| 39 | if (res[0] === BOMChar) {
|
---|
| 40 | res = res.slice(1);
|
---|
| 41 | if (typeof this.options.stripBOM === 'function')
|
---|
| 42 | this.options.stripBOM();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | this.pass = true;
|
---|
| 46 | return res;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | StripBOMWrapper.prototype.end = function() {
|
---|
| 50 | return this.decoder.end();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.