Documentation
¶
Index ¶
- Constants
- Variables
- func CanonicalBytes(model *Model, password string) ([]byte, error)
- func GetCategoryName(id string) string
- func NormalizeMessageID(raw string) (string, error)
- func SanitizeBytes(data []byte, limits Limits) ([]byte, string, error)
- func SubjectFilename(subject string) string
- type Article
- type ArticleRespository
- type Facts
- type File
- type FileFacts
- type Limits
- type Meta
- type Model
- type Parser
- type Segment
- type ValidatedDocument
- type YencDecoder
- type YencHeader
Constants ¶
const ( DefaultMaxNZBBytes int64 = 64 << 20 DefaultMaxFiles = 100_000 DefaultMaxSegments = 5_000_000 DefaultMaxXMLDepth = 32 DefaultMaxMetadataLength = 16 << 10 )
Variables ¶
var ErrArticleNotFound = errors.New("article not found")
ErrArticleNotFound indicates a 430 response from Usenet
var ErrHeaderNotFound = errors.New("yenc header not found")
Functions ¶
func CanonicalBytes ¶ added in v0.10.0
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
GetCategoryName maps Newsnab IDs to human-readable strings.
func NormalizeMessageID ¶ added in v0.10.0
NormalizeMessageID accepts common bracketed and unbracketed representations and returns exactly one pair of angle brackets.
func SanitizeBytes ¶ added in v0.10.0
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
SubjectFilename extracts a useful display name without claiming that an obfuscated subject is a verified source filename.
Types ¶
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 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 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
Helper method to grab the password from the slice of Meta tags
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
type ValidatedDocument ¶ added in v0.10.0
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) 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)