Documentation ¶
Overview ¶
Package textbuffer provides a way to buffer text data based on a number of writes.
Sometimes there is a need to use a buffer with predictable split criteria so that data stays logically solid even if only a single chunk gets its way on the final target writer. Splitting text buffers by size is opposed to such behavior as text lines cut an unpredictable way.
An example of such need is maintaining a log lines buffer before writing into in a rotated file every number of writes.
This package is safe for parallel execution.
Example (Basic) ¶
package main import ( "bytes" "fmt" "github.com/ykhrustalev/textbuffer" ) func main() { var buf bytes.Buffer w := textbuffer.NewWriter(&buf, 2) _, _ = w.Write([]byte("first\n")) fmt.Println("Action#1") fmt.Println(buf.String()) _, _ = w.WriteString("second\n") fmt.Println("Action#2") fmt.Println(buf.String()) _, _ = w.Write([]byte("third\n")) fmt.Println("Action#3") fmt.Println(buf.String()) }
Output: Action#1 Action#2 first second Action#3 first second
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer maintains a buffer which is rotated every number of calls to Write method.
Provides synchronized access to the underline writer
func NewWriter ¶
NewWriter creates an instance with corresponding writer and number of calls before the rotation.