xio

package
v0.5.18 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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)
	}

}

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.

func (*WriteCloserStack) Write

func (w *WriteCloserStack) Write(p []byte) (n int, err error)

Write writes data to the top WriteCloser in the stack. If the stack is empty Write will always succeed.

Jump to

Keyboard shortcuts

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