stream.js 738 B

1234567891011121314151617181920212223242526272829
  1. import { createParser } from "./index.js";
  2. import { ParseError } from "./index.js";
  3. class EventSourceParserStream extends TransformStream {
  4. constructor({ onError, onRetry, onComment } = {}) {
  5. let parser;
  6. super({
  7. start(controller) {
  8. parser = createParser({
  9. onEvent: (event) => {
  10. controller.enqueue(event);
  11. },
  12. onError(error) {
  13. onError === "terminate" ? controller.error(error) : typeof onError == "function" && onError(error);
  14. },
  15. onRetry,
  16. onComment
  17. });
  18. },
  19. transform(chunk) {
  20. parser.feed(chunk);
  21. }
  22. });
  23. }
  24. }
  25. export {
  26. EventSourceParserStream,
  27. ParseError
  28. };
  29. //# sourceMappingURL=stream.js.map