xbstream

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package xbstream provides support for reading and writing xbstream archives

xbstream is archive formatted created by Percona as part of their XtraBackup software suite. The xbstream archive format is their replacement for tar, and unlike tar allows for parallel streams of files to be written to the archive concurrently.

The implementation found in this package is closely modeled from the original C source code, and aims to be interoperable.

Index

Constants

View Source
const (
	// MinimumChunkSize represents the smallest chunk size that xbstream will attempt to fill before flushing to the stream
	MinimumChunkSize = 10 * 1024 * 1024
	// MaxPathLength is the largest file path that can exist within an xbstream archive
	MaxPathLength = 512
	// FlagChunkIgnorable indicates a chunk as ignorable
	FlagChunkIgnorable ChunkFlag = 0x01
)
View Source
const (
	// ChunkTypePayload indicates chunk contains file payload
	ChunkTypePayload = ChunkType('P')
	// ChunkTypeEOF indicates chunk is the eof marker for a file
	ChunkTypeEOF = ChunkType('E')
	// ChunkTypeUnknown indicates the chunk was a type that was unknown to xbstream
	ChunkTypeUnknown = ChunkType(0)
)

Variables

View Source
var (

	// ErrStreamRead indicates an error occurred while parsing an xbstream
	ErrStreamRead = errors.New("xbstream read error")
)

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	ChunkHeader
	io.Reader
}

Chunk encapsulates a ChunkHeader and provides a io.Reader interface for reading the payload described by the Header

type ChunkFlag

type ChunkFlag uint8

ChunkFlag represents a chunks bit flag set

type ChunkHeader

type ChunkHeader struct {
	Magic     []uint8
	Flags     ChunkFlag
	Type      ChunkType // The type of Chunk, Note xbstream archives end with a specific EOF type
	PathLen   uint32
	Path      []uint8
	PayLen    uint64
	PayOffset uint64
	Checksum  uint32
}

ChunkHeader contains the metadata regarding the payload that immediately follows within the archive

type ChunkType

type ChunkType uint8 // Type of Chunk

ChunkType designates a given chunks type

type File

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

File represents a file that is stored within the archive. Exposes an io.WriteCloser interface

func (*File) Close

func (f *File) Close() error

Close flushes any buffered content and closes the file by writing the EOF chunk to the archive

func (*File) Flush

func (f *File) Flush() error

Flush the current contents in the buffer into the archive

func (*File) Write

func (f *File) Write(p []byte) (int, error)

Writes len(p) to the archive, if len(p) < the remaining buffer size the write will be buffered for a later flush. Otherwise contents within the existing buffer will be flushed and then the contents of p will be written

type Reader

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

Reader provides sequential access to chunks from an xbstream. Each chunk returned represents a contiguous set of bytes for a file stored in the xbstream archive. The Next method advances the stream and returns the next chunk in the archive. Each archive then acts as a reader for its contiguous set of bytes

func NewReader

func NewReader(reader io.Reader) *Reader

NewReader creates a new Reader by wrapping the provided reader

func (*Reader) Next

func (r *Reader) Next() (*Chunk, error)

Next advances the Reader and returns the next Chunk. Note: end of input is represented by a specific Chunk type.

type Writer

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

Writer provides to create and writer files in parallel to an xbstream archive

func NewWriter

func NewWriter(writer io.WriteCloser) *Writer

NewWriter returns a new archiver Writer

func (*Writer) Close

func (w *Writer) Close() error

Close the underlying Writer

func (*Writer) Create

func (w *Writer) Create(path string) (*File, error)

Create a new File within the archive represent by path

Jump to

Keyboard shortcuts

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