Streaming

While most use cases for Template involve working with Word, Excel or PowerPoint document, Templater also works with plain text/csv and xml formats.
When working with text/csv format each row is considered a context, which maps closely to working with CSV files.
When dealing with xml format xml element is considered a context, which maps closely to working with XML files.


The main benefit for using Templater as CSV/XML export comes from customization options which are possible in those cases.
Same patterns used in Word and Excel can be applied to work with CSV/XML files.
This opens up possibility for large exports since CSV is much more memory friendly than other two formats.
It also replaces various ad-hoc solutions required to generate XML according to some format. And since it can create large XML export, its also usable in various integration scenarios.

But even with much smaller memory footprint, to create really large documents streaming needs to be utilized, otherwise all data must be in memory upfront which is often not feasible.
If Templater is used in a certain way it can perform streaming and thus flush output and reuse memory.

To perform streaming certain conditions must be met:

  1. Tags which are getting streamed must be last in the document (there can't be other tags before the ones which require streaming). If there are, they need to be processed first, so that the remaining tags can be streamed
  2. Resize must be called multiple times. First to create the extra context and then to resize the actual chunk which is getting processed.
    If special types are used (such as Iterator or IEnumerator/IEnumerable) Templater will implicitly perform this resize multiple times

How it works

All tags before the ones which are streamed must be processed before streaming takes place. Initial tags

Streaming is done by calling resize multiple times:
  1. First by resizing the context (row) once (as shown by green rectangle)
  2. Then by processing (resizing + replacing) the original row again with the appropriate chunk (as shown by red rectangle)

Resize actions



This behavior can be implemented manually, but it is sufficient to pass streaming data type for processing to get this behavior automatically

Back to Features