yenc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

README

yenc

CI Go Reference

Pure-Go, dependency-free yEnc and uuencode decoders and encoders for Usenet binary posts. Builds with CGO_ENABLED=0 using only the Go standard library, and is tested to 100% statement coverage across all supported architectures.

Install

go get github.com/go-newsgroups/yenc

Decode example

package main

import (
	"fmt"

	"github.com/go-newsgroups/yenc"
)

func main() {
	// A yEnc article body runs from =ybegin to =yend. Here we build one with
	// Encode, then decode it back.
	article := yenc.Encode("hello.txt", []byte("hello world"), 128)

	part, err := yenc.Decode(article)
	if err != nil {
		panic(err) // e.g. yenc.ErrCRCMismatch on a corrupt post
	}
	fmt.Printf("name=%q size=%d crc=%08x\n", part.Name, part.Size, part.CRC32)
	fmt.Printf("data=%q\n", part.Data) // "hello world"
}

Encode example

body := yenc.Encode("payload.bin", data, 128) // 128 bytes per line

Encode produces a single-part article body (=ybegin / =yend) with a crc32 trailer. Decode accepts both single-part and multipart bodies, verifies the CRC when the trailer supplies one (returning ErrCRCMismatch on a mismatch), and populates a Part:

type Part struct {
	Name  string // =ybegin name=
	Size  int64  // =ybegin size=
	Line  int    // =ybegin line=
	Part  int    // =ypart / =ybegin part= (0 for single-part)
	Total int    // =ybegin total= (0 if absent)
	Begin int64  // =ypart begin= (1-based; 0 for single-part)
	End   int64  // =ypart end=
	CRC32 uint32 // =yend pcrc32 (part) or crc32 (single); 0 if absent
	Data  []byte // decoded bytes
}

uudecode

out, name, err := yenc.UUDecode(block) // parses "begin <mode> <name>" ... "end"

License

BSD-3-Clause. See LICENSE.

Documentation

Overview

Package yenc implements dependency-free yEnc and uuencode decoders and encoders for Usenet binary posts. It uses only the Go standard library and builds with CGO_ENABLED=0.

Index

Constants

This section is empty.

Variables

View Source
var ErrCRCMismatch = errors.New("yenc: CRC32 mismatch")

ErrCRCMismatch is returned by Decode when the trailer CRC does not match the decoded data.

Functions

func Encode

func Encode(name string, data []byte, lineLen int) []byte

Encode yEnc-encodes data into a single-part article body using lineLen bytes per line (typical 128), with =ybegin/=yend and a crc32 trailer, for the given file name.

func UUDecode

func UUDecode(data []byte) (out []byte, name string, err error)

UUDecode decodes a uuencoded block, returning the bytes and the declared file name from the "begin <mode> <name>" header.

Types

type Part

type Part struct {
	Name  string // =ybegin name=
	Size  int64  // =ybegin size=
	Line  int    // =ybegin line=
	Part  int    // =ypart / =ybegin part= (0 for single-part)
	Total int    // =ybegin total= (0 if absent)
	Begin int64  // =ypart begin= (1-based; 0 for single-part)
	End   int64  // =ypart end=
	CRC32 uint32 // =yend pcrc32 (part) or crc32 (single); 0 if absent
	Data  []byte // decoded bytes
}

Part is one decoded yEnc part (single-part posts have Part==0).

func Decode

func Decode(data []byte) (*Part, error)

Decode decodes one yEnc-encoded article body (the region from =ybegin to =yend). It verifies the CRC when the trailer provides one, returning ErrCRCMismatch on a mismatch (Part is still returned so callers may inspect it).

Jump to

Keyboard shortcuts

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