Skip to content

Input Output Streaming

JPVenson edited this page Jun 21, 2022 · 1 revision

Morestachio is build around the idea of streaming its input and output parameters. There is a balance to be held between having enough information in memory to construct the renderer and consuming the least amount of memory.

Input Streaming

In its current form, the morestachio tokenizer constructs its tokens by using a ITemplateContainer. The default implementation is the StringTemplateContainer extending the TemplateContainerBase where an base tokenizer is implemented. The base tokenizer does copy its information from the input into memory while reading the stream provided. This implementation is a read-only-forward strategy so that the underlying stream does not need to keep any read data but it does need to know the length in advance.

Output Streaming

For Output the streaming idea is completely implemented. By using the IByteCounterStream morestachio does write into an abstracted stream on byte level. The output is also completely write-forward only and supports .net2.1 ReadOnlySpan<byte>. There are multiple implementations for this stream, according to your specific use-case:

  • ByteCounterStream uses an System.IO.Stream
  • ByteCounterStringBuilder uses an System.Text.StringBuilder. Best for pure in-memory generation
  • ByteCounterTextWriter uses an System.IO.TextWriter
  • NullStream does not write anything