yenc

package module
Version: v0.0.0-...-3e21eb3 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2017 License: MIT Imports: 10 Imported by: 1

README

yenc

-- import "github.com/andrewstuart/yenc"

Package yenc implements readers writers for the YENC encoding format.

Usage

var (
	ErrBadCRC    = fmt.Errorf("CRC check error")
	ErrWrongSize = fmt.Errorf("size check error")
)

Error constants

type Reader
type Reader struct {
	Length          int
	CRC             hash.Hash32
	Headers, Footer *YENCHeader
}

Reader implements the io.Reader methods for an underlying YENC document/stream. It additionally exposes some of the metadata that may be useful for consumers.

func NewReader
func NewReader(r io.Reader) *Reader

NewReader returns a reader from an input reader.

func (*Reader) Read
func (d *Reader) Read(p []byte) (bytesRead int, err error)
type Writer
type Writer struct {
	CRC            hash.Hash32
	Length, Line   int
	Name           string
	Header, Footer *YENCHeader
}
func NewWriter
func NewWriter(w io.Writer) *Writer
func (*Writer) Close
func (w *Writer) Close() error
func (*Writer) Write
func (w *Writer) Write(p []byte) (written int, err error)
type YENCHeader
type YENCHeader map[string]string
func ReadYENCHeader
func ReadYENCHeader(br *bufio.Reader) (*YENCHeader, error)
func (*YENCHeader) Add
func (y *YENCHeader) Add(k, v string)
func (*YENCHeader) Get
func (y *YENCHeader) Get(k string) string
func (*YENCHeader) String
func (y *YENCHeader) String() string

Documentation

Overview

Package yenc implements readers writers for the YENC encoding format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrBadCRC

type ErrBadCRC struct {
	Expected, Actual uint32
}

ErrBadCRC is returned when a CRC does not match

func (ErrBadCRC) Error

func (e ErrBadCRC) Error() string

Error implements error

type ErrWrongSize

type ErrWrongSize struct {
	Expected, Actual int
}

ErrWrongSize is returned when a part or file is not the expected full size

func (ErrWrongSize) Error

func (e ErrWrongSize) Error() string

Error implements error

type Header map[string]string

Header is a map type for reading a serialized yenc header.

func ReadYENCHeader

func ReadYENCHeader(bs []byte) (*Header, int)

ReadYENCHeader accepts a byte slice and returns a YENCHeader or any error encountered while decoding, and the header length so that the consumer can ignore the appropriate bytes.

func (*Header) Get

func (y *Header) Get(k string) string

Get returns the string for a key

func (*Header) Put

func (y *Header) Put(k, v string)

Put creates a string entry for a k, v pair

func (*Header) String

func (y *Header) String() string

String implements the stringer interface, printing the proper yenc header

type Reader

type Reader struct {
	Length          int
	ExpectedCRC     uint32
	CRC             hash.Hash32
	Headers, Footer *Header
	// contains filtered or unexported fields
}

Reader implements the io.Reader methods for an underlying YENC document/stream. It additionally exposes some of the metadata that may be useful for consumers.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a reader from an input reader.

func (*Reader) CheckCRC

func (d *Reader) CheckCRC() error

CheckCRC makes sure the CRC matches and returns an error if not

func (*Reader) Read

func (d *Reader) Read(p []byte) (bytesRead int, err error)

type Writer

type Writer struct {
	CRC            hash.Hash32
	Length, Line   int
	Name           string
	Header, Footer *Header
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.Writer) *Writer

func (*Writer) Close

func (w *Writer) Close() error

func (*Writer) Write

func (w *Writer) Write(p []byte) (written int, err error)

Jump to

Keyboard shortcuts

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