func New(wd string, ss Strategizer, gro ...GrabberOption) (*Grabber, error) { if wd == "" { return nil, MissingWorkDirError } mx := new(sync.RWMutex) g := &Grabber{ wd: wd, s: ss, writeState: mx, readState: mx.RLocker(), qIn: make(chan Segmenter, 100), // TODO(negz): Determine best buffer len. qOut: make(chan Segmenter, 100), maxRetry: 3, doneMx: new(sync.Mutex), pp: make(chan bool), decoder: yenc.NewDecoder, // TODO(negz): Detect encoding. fileCreator: createSegmentFile, grabT: new(tomb.Tomb), enqueueT: new(tomb.Tomb), } for _, o := range gro { if err := o(g); err != nil { return nil, err } } if g.name == "" { return nil, MissingNameError } g.hash = util.HashString(g.name) return g, nil }
func NewFile(nf *nzb.File, g Grabberer, filter ...*regexp.Regexp) Filer { mx := new(sync.RWMutex) f := &File{ nf: nf, g: g, hash: util.HashString(nf.Subject), segments: make([]Segmenter, 0, len(nf.Segments)), writeState: mx, readState: mx.RLocker(), doneMx: new(sync.Mutex), required: true, } for _, ns := range nf.Segments { f.segments = append(f.segments, NewSegment(ns, f)) } if par2RE.MatchString(nf.Subject) { f.par2 = true f.required = false f.Pause() } for _, r := range filter { if r.MatchString(nf.Subject) { f.filtered = true f.required = false f.Pause() } } if f.required { f.g.FileRequired() } return f }
func (s *Segment) Hash() string { return util.HashString(s.ns.ArticleID) }