Skip to content

Conversation

Ohadleshno15
Copy link

@Ohadleshno15 Ohadleshno15 commented Aug 6, 2025

Add Configurable Text Streaming Mode

Summary

Adds streamText option to enable zero-buffering streaming of email text content instead of accumulating in memory.

Changes

  • New Option: streamText: true - streams each text part individually
  • Default Behavior: streamText: false - maintains backward compatibility
  • Zero Buffering: Text content streams directly without memory accumulation
  • Individual Parts: Each MIME text part (plain/html) emits separately

Usage

// Streaming mode - no memory buffering
const parser = new MailParser({ streamText: true });
parser.on('data', (data) => {
  if (data.type === 'text') {
    data.content.pipe(process.stdout); // Stream directly
  }
});

// Traditional mode (default) - backward compatible
const parser = new MailParser();
parser.on('data', (data) => {
  if (data.type === 'text') {
    console.log(data.text, data.textAsHtml); // Aggregated content
  }
});

Tests

  • ✅ Streaming mode validation
  • ✅ Individual part content verification
  • ✅ Backward compatibility assurance

Benefits: Handles large emails efficiently without memory accumulation while maintaining full backward compatibility.

@CLAassistant
Copy link

CLAassistant commented Aug 6, 2025

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants