nzb

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxNZBBytes       int64 = 64 << 20
	DefaultMaxFiles                = 100_000
	DefaultMaxSegments             = 5_000_000
	DefaultMaxXMLDepth             = 32
	DefaultMaxMetadataLength       = 16 << 10
)

Variables

View Source
var ErrArticleNotFound = errors.New("article not found")

ErrArticleNotFound indicates a 430 response from Usenet

View Source
var ErrHeaderNotFound = errors.New("yenc header not found")

Functions

func CanonicalBytes added in v0.10.0

func CanonicalBytes(model *Model, password string) ([]byte, error)

CanonicalBytes serializes a validated NZB model deterministically using the Pesto 0.8.6 layout. Message IDs are stored internally with angle brackets and written to NZB segment bodies without them, as required by that format.

func GetCategoryName added in v0.5.0

func GetCategoryName(id string) string

GetCategoryName maps Newsnab IDs to human-readable strings.

func NormalizeMessageID added in v0.10.0

func NormalizeMessageID(raw string) (string, error)

NormalizeMessageID accepts common bracketed and unbracketed representations and returns exactly one pair of angle brackets.

func SanitizeBytes added in v0.10.0

func SanitizeBytes(data []byte, limits Limits) ([]byte, string, error)

SanitizeBytes validates an NZB and emits the canonical private form used by worker uploads and GoNZBNet manifest reconstruction. Descriptive head metadata is intentionally discarded; only the extraction password remains.

func SubjectFilename added in v0.10.0

func SubjectFilename(subject string) string

SubjectFilename extracts a useful display name without claiming that an obfuscated subject is a verified source filename.

Types

type Article added in v0.4.0

type Article struct {
	MessageID string
	Size      int
}

Article respresents the metadata for a single Usenet post.

type ArticleRespository added in v0.4.0

type ArticleRespository interface {
	FetchBody(messageID string) (io.Reader, error)
	Authenticate() error
	Close() error
}

ArticleRepository defines the contract for fetching data from Usenet.

type Facts added in v0.10.0

type Facts struct {
	SizeBytes    int64       `json:"size_bytes"`
	FileCount    int         `json:"file_count"`
	SegmentCount int         `json:"segment_count"`
	Groups       []string    `json:"groups"`
	Poster       string      `json:"poster"`
	PostedAt     time.Time   `json:"posted_at"`
	Title        string      `json:"title"`
	Password     string      `json:"-"`
	HasPAR2      bool        `json:"has_par2"`
	HasNFO       bool        `json:"has_nfo"`
	Files        []FileFacts `json:"files"`
}

Facts contains trustworthy values derived from the original NZB.

type File added in v0.4.0

type File struct {
	Subject  string    `xml:"subject,attr"`
	Poster   string    `xml:"poster,attr"`
	Date     int64     `xml:"date,attr"`
	Groups   []string  `xml:"groups>group"`
	Segments []Segment `xml:"segments>segment"`
}

type FileFacts added in v0.10.0

type FileFacts struct {
	Name         string    `json:"name"`
	Subject      string    `json:"subject"`
	Poster       string    `json:"poster"`
	PostedAt     time.Time `json:"posted_at"`
	Groups       []string  `json:"groups"`
	SizeBytes    int64     `json:"size_bytes"`
	SegmentCount int       `json:"segment_count"`
}

type Limits added in v0.10.0

type Limits struct {
	MaxBytes          int64
	MaxFiles          int
	MaxSegments       int
	MaxXMLDepth       int
	MaxMetadataLength int
}

Limits bounds the amount of work performed while validating an NZB.

func DefaultLimits added in v0.10.0

func DefaultLimits() Limits

type Meta added in v0.4.1

type Meta struct {
	Type    string `xml:"type,attr"`
	Content string `xml:",chardata"`
}

type Model added in v0.4.0

type Model struct {
	XMLName xml.Name `xml:"nzb"`
	Meta    []Meta   `xml:"head>meta"`
	Files   []File   `xml:"file"`
}

func (*Model) GetPassword added in v0.4.1

func (n *Model) GetPassword() string

Helper method to grab the password from the slice of Meta tags

type Parser

type Parser struct{}

func NewParser

func NewParser() *Parser

func (*Parser) Parse

func (p *Parser) Parse(r io.Reader) (*Model, error)

func (*Parser) ParseFile

func (p *Parser) ParseFile(nzbPath string) (*Model, error)

type Segment added in v0.4.0

type Segment struct {
	XMLName   xml.Name `xml:"segment"`
	Number    int      `xml:"number,attr"`
	Bytes     int64    `xml:"bytes,attr"`
	MessageID string   `xml:",chardata"`
}

func SortedSegments added in v0.10.0

func SortedSegments(file File) []Segment

type ValidatedDocument added in v0.10.0

type ValidatedDocument struct {
	Model *Model
	Facts Facts
}

func ValidateBytes added in v0.10.0

func ValidateBytes(data []byte, limits Limits) (*ValidatedDocument, error)

ValidateBytes parses and validates one complete NZB XML document. Message IDs are normalized in the returned model to their bracketed representation.

type YencDecoder added in v0.4.0

type YencDecoder struct {
	PartNumber int
	TotalParts int
	PartOffset int64
	PartEnd    int64
	FileSize   int64
	FileName   string
	// contains filtered or unexported fields
}

func NewYencDecoder added in v0.4.0

func NewYencDecoder(r io.Reader) *YencDecoder

func (*YencDecoder) DiscardHeader added in v0.4.0

func (d *YencDecoder) DiscardHeader() error

func (*YencDecoder) Read added in v0.4.0

func (d *YencDecoder) Read(p []byte) (n int, err error)

func (*YencDecoder) Verify added in v0.4.0

func (d *YencDecoder) Verify() error

type YencHeader added in v0.7.0

type YencHeader struct {
	PartNumber int
	TotalParts int
	PartOffset int64
	PartEnd    int64
	FileSize   int64
	FileName   string
}

func ReadYencHeader added in v0.7.0

func ReadYencHeader(r io.Reader) (YencHeader, error)

Jump to

Keyboard shortcuts

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