StringWriter.js 675 B

1234567891011121314151617181920212223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.StringWriter = void 0;
  4. const stream_1 = require("stream");
  5. class StringWriter extends stream_1.Writable {
  6. constructor() {
  7. super(...arguments);
  8. this.buf = Buffer.alloc(0);
  9. }
  10. _write(chunk, _, callback) {
  11. if (chunk instanceof Buffer) {
  12. this.buf = Buffer.concat([this.buf, chunk]);
  13. callback(null);
  14. }
  15. else {
  16. callback(new Error("StringWriter expects chunks of type 'Buffer'."));
  17. }
  18. }
  19. getText(encoding) {
  20. return this.buf.toString(encoding);
  21. }
  22. }
  23. exports.StringWriter = StringWriter;