Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bom-handling.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. var BOMChar = '\uFEFF';
  3. exports.PrependBOM = PrependBOMWrapper
  4. function PrependBOMWrapper(encoder, options) {
  5. this.encoder = encoder;
  6. this.addBOM = true;
  7. }
  8. PrependBOMWrapper.prototype.write = function(str) {
  9. if (this.addBOM) {
  10. str = BOMChar + str;
  11. this.addBOM = false;
  12. }
  13. return this.encoder.write(str);
  14. }
  15. PrependBOMWrapper.prototype.end = function() {
  16. return this.encoder.end();
  17. }
  18. //------------------------------------------------------------------------------
  19. exports.StripBOM = StripBOMWrapper;
  20. function StripBOMWrapper(decoder, options) {
  21. this.decoder = decoder;
  22. this.pass = false;
  23. this.options = options || {};
  24. }
  25. StripBOMWrapper.prototype.write = function(buf) {
  26. var res = this.decoder.write(buf);
  27. if (this.pass || !res)
  28. return res;
  29. if (res[0] === BOMChar) {
  30. res = res.slice(1);
  31. if (typeof this.options.stripBOM === 'function')
  32. this.options.stripBOM();
  33. }
  34. this.pass = true;
  35. return res;
  36. }
  37. StripBOMWrapper.prototype.end = function() {
  38. return this.decoder.end();
  39. }