11cb0ef41Sopenharmony_ci"use strict"; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_civar BOMChar = '\uFEFF'; 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciexports.PrependBOM = PrependBOMWrapper 61cb0ef41Sopenharmony_cifunction PrependBOMWrapper(encoder, options) { 71cb0ef41Sopenharmony_ci this.encoder = encoder; 81cb0ef41Sopenharmony_ci this.addBOM = true; 91cb0ef41Sopenharmony_ci} 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciPrependBOMWrapper.prototype.write = function(str) { 121cb0ef41Sopenharmony_ci if (this.addBOM) { 131cb0ef41Sopenharmony_ci str = BOMChar + str; 141cb0ef41Sopenharmony_ci this.addBOM = false; 151cb0ef41Sopenharmony_ci } 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci return this.encoder.write(str); 181cb0ef41Sopenharmony_ci} 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciPrependBOMWrapper.prototype.end = function() { 211cb0ef41Sopenharmony_ci return this.encoder.end(); 221cb0ef41Sopenharmony_ci} 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci//------------------------------------------------------------------------------ 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciexports.StripBOM = StripBOMWrapper; 281cb0ef41Sopenharmony_cifunction StripBOMWrapper(decoder, options) { 291cb0ef41Sopenharmony_ci this.decoder = decoder; 301cb0ef41Sopenharmony_ci this.pass = false; 311cb0ef41Sopenharmony_ci this.options = options || {}; 321cb0ef41Sopenharmony_ci} 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ciStripBOMWrapper.prototype.write = function(buf) { 351cb0ef41Sopenharmony_ci var res = this.decoder.write(buf); 361cb0ef41Sopenharmony_ci if (this.pass || !res) 371cb0ef41Sopenharmony_ci return res; 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci if (res[0] === BOMChar) { 401cb0ef41Sopenharmony_ci res = res.slice(1); 411cb0ef41Sopenharmony_ci if (typeof this.options.stripBOM === 'function') 421cb0ef41Sopenharmony_ci this.options.stripBOM(); 431cb0ef41Sopenharmony_ci } 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci this.pass = true; 461cb0ef41Sopenharmony_ci return res; 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ciStripBOMWrapper.prototype.end = function() { 501cb0ef41Sopenharmony_ci return this.decoder.end(); 511cb0ef41Sopenharmony_ci} 521cb0ef41Sopenharmony_ci 53