nzb

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

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

Go to latest
Published: Mar 24, 2018 License: MIT Imports: 7 Imported by: 1

README

nzb

Build Status Godoc Reference Coverage Status Go Report Card codebeat badge

Golang library for dealing with NZB files

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// string describing who posted the NZB
	Poster string `xml:"poster,attr"`
	// unix formatted date that the NZB was posted
	Date int `xml:"date,attr"`
	// describes what the contents of the NZB file are
	Subject string `xml:"subject,attr"`
	// usenet groups associated with the NZB
	Groups []string `xml:"groups>group,internalxml"`
	// actual file segments to be downloaded
	Segments []Segment `xml:"segments>segment"`
}

File describes the file elements within an NZB. It has appropriate tags and methods to enable deserialisation from XML.

func (*File) ApproximatedName

func (f *File) ApproximatedName() (string, error)

ApproximatedName returns the approximated name of the file that an NZB file entry represents.

func (*File) Size

func (f *File) Size() (size int64)

Size returns the size in bytes of the file. It returns the sum of the sizes of its segments.

type Meta

type Meta map[string]string

Meta is a map[string]string that implements UnmarshalXML to enable appropriate unmarshalling of XML metadata tags

func (Meta) MarshalXML

func (m Meta) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements xml.Marshaler for the Meta type

func (*Meta) UnmarshalXML

func (m *Meta) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML implements xml.Unmarshaler for the Meta type

type NZB

type NZB struct {
	// the name of the XML tag this represents (nzb)
	XMLName xml.Name `xml:"nzb"`
	// XML metadata associated with the NZB file
	Meta Meta `xml:"head>meta"`
	// NZB file entries contained within this NZB file
	Files []File `xml:"file"`
}

NZB represents a usenet NZB file the struct has appropriate XML tags and methods to enable unmarshalling

func FromBytes

func FromBytes(data []byte) (*NZB, error)

FromBytes parses a NZB from a byte slice

func FromFile

func FromFile(path string) (*NZB, error)

FromFile parses a NZB from a file

func FromReader

func FromReader(buf io.Reader) (*NZB, error)

FromReader parses a NZB from an io.Reader

func FromString

func FromString(data string) (*NZB, error)

FromString parses a NZB from a string

func (NZB) Bytes

func (n NZB) Bytes() ([]byte, error)

Bytes returns an NZB entry encoded in its original XML format, as a byte slice

func (NZB) BytesReader

func (n NZB) BytesReader() (io.Reader, error)

BytesReader returns an io.Reader containing an NZB entry encoded in its original XML format

func (NZB) Size

func (nzb NZB) Size() (size int64)

Size returns the sum of the file sizes within the NZB

func (NZB) String

func (n NZB) String() (string, error)

String returns an NZB entry encoded in its original XML format, as a string

type Segment

type Segment struct {
	// number of the segment relative to the file
	Number int `xml:"number,attr"`
	// size of the segment in bytes
	Size int `xml:"bytes,attr"`
	// identifier of the segment
	ID string `xml:",innerxml"`
}

Segment describes a piece of an NZB file, to be downloaded separately. It has appropriate tags and methods to enable deserialisation from XML.

Jump to

Keyboard shortcuts

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