streams.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var streams_exports = {};
  20. __export(streams_exports, {
  21. StringWriteStream: () => StringWriteStream
  22. });
  23. module.exports = __toCommonJS(streams_exports);
  24. var import_stream = require("stream");
  25. var import_util = require("../../util");
  26. class StringWriteStream extends import_stream.Writable {
  27. constructor(output, stdio) {
  28. super();
  29. this._output = output;
  30. this._prefix = stdio === "stdout" ? "" : "[err] ";
  31. }
  32. _write(chunk, encoding, callback) {
  33. let text = (0, import_util.stripAnsiEscapes)(chunk.toString());
  34. if (text.endsWith("\n"))
  35. text = text.slice(0, -1);
  36. if (text)
  37. this._output.push(this._prefix + text);
  38. callback();
  39. }
  40. }
  41. // Annotate the CommonJS export names for ESM import in node:
  42. 0 && (module.exports = {
  43. StringWriteStream
  44. });