yenc

package module
v0.0.0-...-bc91c59 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 8 Imported by: 0

README ΒΆ

Go yEncode (yenc) decoder module

A Go port of the decoder functionality of yencode 0.46 that decodes binary data for Usenet (NNTP) transfer.

Forked from https://github.com/go-yenc/yenc and enhanced with more robust parsing and error handling. Encoding features ommitted from this fork.

πŸ“š Guides & Documentation

Example use
go get github.com/ovrlord-app/go-yenc-decoder
package main

import (
	"fmt"
	"io"
	"os"

	yenc "github.com/ovrlord-app/go-yenc-decoder"
)

func decodePart(articleBody []byte, outFile *os.File) (int64, error) {
	decoder, err := yenc.Decode(articleBody, yenc.DecodeWithPrefixData())
	if err != nil {
		return 0, fmt.Errorf("yenc: %w", err)
	}

	written, err := io.Copy(outFile, decoder)
	if err != nil {
		return written, err
	}

	return written, nil
}

License

This project is licensed under the MIT - see the LICENSE file for details.

Support

Documentation ΒΆ

Overview ΒΆ

Copied from https://github.com/go-yenc/yenc and enhanced with more robust parsing and error handling. The original license is MIT.

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var BufferLimit = 256 * 1024

Max number of bytes per line (ends in LF and includes the LF) when decoding yEnc data stream. Set to 256 KiB so the ring buffer can hold many complete yEnc lines, avoiding boundary issues that caused stalling with the original 4 KiB default.

View Source
var ErrBufferTooSmall = errors.New("buffer too small")
View Source
var ErrDataCorruption = errors.New("data corruption detected")
View Source
var ErrInvalidFormat = errors.New("not a valid yEncode formatted data stream")
View Source
var ErrRejectPrefixData = errors.New("yEncode not started at the beginning of the data stream")
View Source
var LineLimit uint64 = 128

Max number of bytes per line (ends in LF but NOT include the LF) when encoding yEnc data stream. Default is 128 which is a commonly acceptable limit for probably all known NNTP and yEncode implementations.

Functions ΒΆ

func ApplyOption ΒΆ

func ApplyOption[T any, O ~func(*T)](opts *T, options []O, defaults ...O) *T

func NewOption ΒΆ

func NewOption[T any, O ~func(*T)](options []O, defaults ...O) *T

Types ΒΆ

type DecodeOption ΒΆ

type DecodeOption func(*Decoder)

func DecodeWithBuffer ΒΆ

func DecodeWithBuffer(b []byte) DecodeOption

func DecodeWithBufferSize ΒΆ

func DecodeWithBufferSize(size int) DecodeOption

func DecodeWithPrefixData ΒΆ

func DecodeWithPrefixData() DecodeOption

type Decoder ΒΆ

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

func Decode ΒΆ

func Decode(r io.Reader, options ...DecodeOption) (decoder *Decoder, err error)

func (*Decoder) Buffer ΒΆ

func (d *Decoder) Buffer() []byte

Get the remaining bytes in the buffer consumed but not decoded.

func (*Decoder) CRC32 ΒΆ

func (d *Decoder) CRC32() uint32

CRC32 checksum of the preceeding data decoded so far.

func (*Decoder) Header ΒΆ

func (d *Decoder) Header() *Header

func (*Decoder) Read ΒΆ

func (d *Decoder) Read(b []byte) (n int, err error)
type Header struct {
	Name  string // Name of the final output file
	Size  uint64 // Final, overall file size (of all parts decoded)
	Part  uint64 // Part number (starts from 1)
	Total uint64 // Total number of parts. Optional even for multipart.
	Line  uint64 // Average line length
	Begin uint64 // Part begin offset (0-indexed). Note the begin keyword in the =ypart line is 1-indexed.
	End   uint64 // Part end offset (0-indexed, exclusive)
}

yEncode header information

Jump to

Keyboard shortcuts

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