...

Source file src/github.com/launchdarkly/go-jsonstream/v3/jwriter/writer_init_default.go

Documentation: github.com/launchdarkly/go-jsonstream/v3/jwriter

     1  package jwriter
     2  
     3  import "io"
     4  
     5  // NewWriter creates a Writer that will buffer its entire output in memory.
     6  //
     7  // This function returns the struct by value (Writer, not *Writer). This avoids the overhead of a
     8  // heap allocation since, in typical usage, the Writer will not escape the scope in which it was
     9  // declared and can remain on the stack.
    10  func NewWriter() Writer {
    11  	return Writer{tw: newTokenWriter()}
    12  }
    13  
    14  // NewStreamingWriter creates a Writer that will buffer a limited amount of its output in memory
    15  // and dump the output to the specified io.Writer whenever the buffer is full. You should also
    16  // call Flush at the end of your output to ensure that any remaining buffered output is flushed.
    17  //
    18  // If the Writer returns an error at any point, it enters a failed state and will not try to
    19  // write any more data to the target.
    20  //
    21  // This function returns the struct by value (Writer, not *Writer). This avoids the overhead of a
    22  // heap allocation since, in typical usage, the Writer will not escape the scope in which it was
    23  // declared and can remain on the stack.
    24  func NewStreamingWriter(target io.Writer, bufferSize int) Writer {
    25  	return Writer{tw: newStreamingTokenWriter(target, bufferSize)}
    26  }
    27  

View as plain text