Documentation
¶
Overview ¶
Package xio provides tools to handle I/O operations. It contains the WriteCloserStack type supporting combining multiple WriterClosers as single io.WriteCloser.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WriteCloserStack ¶
type WriteCloserStack struct {
Stack []io.WriteCloser
}
WriteCloserStack allows to support multiple WriteClosers to be handled as single WriteCloser.
Example ¶
package main
import (
"io"
"os"
"github.com/ulikunitz/xz"
"github.com/ulikunitz/xz/xio"
)
func main() {
wcStack := xio.NewWriteCloserStack()
defer wcStack.Close()
f, err := os.CreateTemp("", "example_write_closer_stack-*.xz")
if err != nil {
panic(err)
}
wcStack.Push(f)
z, err := xz.NewWriter(f)
if err != nil {
panic(err)
}
wcStack.Push(z)
_, err = io.WriteString(wcStack, "The fox jumps over the lazy dog.\n")
if err != nil {
panic(err)
}
err = wcStack.Close()
if err != nil {
panic(err)
}
}
Output:
func NewWriteCloserStack ¶
func NewWriteCloserStack() *WriteCloserStack
NewWriteCloserStack creates a new WriteCloserStack. It will have an an empty stack.
func (*WriteCloserStack) Close ¶
func (w *WriteCloserStack) Close() error
Close closes all writers on the stack and combines the errors. It will clear the stack.
func (*WriteCloserStack) Push ¶
func (w *WriteCloserStack) Push(wc io.WriteCloser)
Push adds a new WriteCloser to the top of the stack. It panics if the WriteCloser is nil.