writer

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2024 License: Apache-2.0 Imports: 2 Imported by: 14

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorAbort

func ErrorAbort(err error) error

ErrorAbort .

func IngoreError

func IngoreError(error) error

IngoreError .

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer .

Example
buf := NewBuffer(&testWriter{2}, 4)
n, err := buf.WriteN(1, 2, 3, 4, 5, 6, 7, 8, 9)
fmt.Printf("writes: %d, buffered: %v, err: %s\n", n, buf.buf, err)

err = buf.Close()
fmt.Println(err)
Output:

WriteN size: 4, data: [1 2 3 4]
writes: 8, buffered: [5 6 7 8], err: buffer max capacity
Close
buffer max capacity
Example (For)
buf := NewBuffer(&testWriter{100}, 3)
data := make([]interface{}, 10, 10)
for i := range data {
	data[i] = i
}
for i := 0; i < 10; i++ {
	n, err := buf.WriteN(data[0 : 1+i%10]...)
	if err != nil {
		fmt.Println(n, buf.buf, err)
		break
	}
}
err := buf.Close()
fmt.Println(buf.buf, err)
Output:

WriteN size: 3, data: [0 0 1]
WriteN size: 3, data: [0 1 2]
WriteN size: 3, data: [0 1 2]
WriteN size: 3, data: [3 0 1]
WriteN size: 3, data: [2 3 4]
WriteN size: 3, data: [0 1 2]
WriteN size: 3, data: [3 4 5]
WriteN size: 3, data: [0 1 2]
WriteN size: 3, data: [3 4 5]
WriteN size: 3, data: [6 0 1]
WriteN size: 3, data: [2 3 4]
WriteN size: 3, data: [5 6 7]
WriteN size: 3, data: [0 1 2]
WriteN size: 3, data: [3 4 5]
WriteN size: 3, data: [6 7 8]
WriteN size: 3, data: [0 1 2]
WriteN size: 3, data: [3 4 5]
WriteN size: 3, data: [6 7 8]
WriteN size: 1, data: [9]
Close
[] <nil>
Example (Write)
buf := NewBuffer(&testWriter{10}, 3)
n, err := buf.WriteN(1, 2, 3, 4, 5)
fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err)

n, err = buf.WriteN(6)
fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err)

n, err = buf.WriteN(7, 8, 9)
fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err)

n, err = buf.WriteN(10, 11)
fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err)

n, err = buf.WriteN(10, 11)
fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err)
Output:

WriteN size: 3, data: [1 2 3]
writes: 5, buffered: [4 5], err: <nil>
WriteN size: 3, data: [4 5 6]
writes: 1, buffered: [], err: <nil>
writes: 3, buffered: [7 8 9], err: <nil>
WriteN size: 3, data: [7 8 9]
writes: 2, buffered: [10 11], err: <nil>
WriteN size: 3, data: [10 11 10]
writes: 2, buffered: [11], err: <nil>

func NewBuffer

func NewBuffer(w Writer, max int) *Buffer

NewBuffer .

func (*Buffer) Close

func (b *Buffer) Close() error

Close .

func (*Buffer) Data

func (b *Buffer) Data() []interface{}

Data .

func (*Buffer) Flush

func (b *Buffer) Flush() error

Flush .

func (*Buffer) Size

func (b *Buffer) Size() int

Size .

func (*Buffer) Write

func (b *Buffer) Write(data interface{}) error

Write .

func (*Buffer) WriteN

func (b *Buffer) WriteN(data ...interface{}) (int, error)

WriteN returns the number of buffers written to the data. if a Flush error occurs, the error will be returned

type ErrorHandler

type ErrorHandler func(error) error

ErrorHandler .

type Writer

type Writer interface {
	Write(data interface{}) error
	WriteN(data ...interface{}) (int, error)
	Close() error
}

Writer .

func ParallelBatch

func ParallelBatch(
	writers func(i uint64) Writer,
	parallelism,
	size uint64,
	timeout time.Duration,
	errorh ErrorHandler,
) Writer

ParallelBatch .

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL