rapidyenc

package module
v0.0.0-...-354d854 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	StateCRLF     = State(C.RYDEC_STATE_CRLF)
	StateEQ       = State(C.RYDEC_STATE_EQ)
	StateCR       = State(C.RYDEC_STATE_CR)
	StateNone     = State(C.RYDEC_STATE_NONE)
	StateCRLFDT   = State(C.RYDEC_STATE_CRLFDT)
	StateCRLFDTCR = State(C.RYDEC_STATE_CRLFDTCR)
	StateCRLFEQ   = State(C.RYDEC_STATE_CRLFEQ) // may actually be "\r\n.=" in raw Decoder
)
View Source
const (
	EndNone    = End(C.RYDEC_END_NONE)    // end not reached
	EndControl = End(C.RYDEC_END_CONTROL) // \r\n=y sequence found, src points to byte after 'y'
	EndArticle = End(C.RYDEC_END_ARTICLE) // \r\n.\r\n sequence found, src points to byte after last '\n'
)

Variables

View Source
var (
	ErrDataMissing    = errors.New("no binary data")
	ErrDataCorruption = errors.New("data corruption detected") // .\r\n reached before =yend
	ErrCrcMismatch    = errors.New("crc32 mismatch")
)

Functions

func MaxLength

func MaxLength(length, lineLength int) int

func ReleaseDecoder

func ReleaseDecoder(dec *Decoder)

ReleaseDecoder returns dec acquired via AcquireDecoder to Decoder pool.

It is forbidden accessing dec and/or its members after returning it to Decoder pool.

Types

type Decoder

type Decoder struct {
	State State
	// contains filtered or unexported fields
}

func AcquireDecoder

func AcquireDecoder() *Decoder

AcquireDecoder returns an empty Decoder instance from Decoder pool.

The returned Decoder instance may be passed to ReleaseDecoder when it is no longer needed. This allows Decoder recycling, reduces GC pressure and usually improves performance.

func NewDecoder

func NewDecoder(bufSize int) *Decoder

func (*Decoder) Meta

func (d *Decoder) Meta() Meta

func (*Decoder) Read

func (d *Decoder) Read(p []byte) (int, error)

func (*Decoder) Reset

func (d *Decoder) Reset()

func (*Decoder) SetReader

func (d *Decoder) SetReader(reader io.Reader)

func (*Decoder) Transform

func (d *Decoder) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)

Transform starts by reading line-by-line to parse yEnc headers until it encounters yEnc data. It then incrementally decodes chunks of yEnc encoded data before returning to line-by-line processing for the footer and EOF pattern (.\r\n)

type Encoder

type Encoder struct {
	LineLength int
}

func NewEncoder

func NewEncoder() *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(src []byte) []byte

type End

type End int

End is the State for incremental decoding, whether the end of the yEnc data was reached

func DecodeIncremental

func DecodeIncremental(dst, src []byte, state *State) (nDst, nSrc int, end End, err error)

DecodeIncremental stops decoding when a yEnc/NNTP end sequence is found

type Format

type Format int
const (
	FormatUnknown Format = iota
	FormatYenc
	FormatUU
)

type Meta

type Meta struct {
	Size  int64  // Total size of the file
	Begin int64  // Part begin offset (0-indexed)
	End   int64  // Part end offset (0-indexed, exclusive)
	Hash  uint32 // CRC32 hash of the decoded data
	Name  string // Name of the file
}

Meta is the result of parsing the yEnc headers (ybegin, ypart, yend)

type State

type State int

State is the current Decoder State, the values refer to the previously seen characters in the stream, which influence how some sequences need to be handled.

The shorthands represent: CR (\r), LF (\n), EQ (=), DT (.)

Jump to

Keyboard shortcuts

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