func (self *httpBackendStream) Read(from uint, to uint) (stream.Stream, error) { if from == to { return stream.Empty(), nil } resp, err := self.p.Post(fmt.Sprintf(self.readUrl, from, to), nil) if err != nil { return nil, err } defer resp.Body.Close() res := arrErrorObj{} if err := json.NewDecoder(resp.Body).Decode(&res); err != nil { return nil, err } if res.Err != "" { return nil, errors.New(res.Err) } r := make([]stream.Event, len(res.Events)) for i, v := range res.Events { r[i] = stream.Event([]byte(v)) } return stream.List(r), nil }
func (self *memStreamObj) Read(from uint, to uint) (stream.Stream, error) { if from == to { return stream.Empty(), nil } self.lock.Lock() defer self.lock.Unlock() l := len(self.data) if _, _, err := convRange(int(from), int(to), l, "memStreamObj.Read"); err != nil { return nil, err } return stream.List(self.data[from:to]), nil }
func (self *ledisStreamObj) Read(from uint, to uint) (stream.Stream, error) { if from == to { return stream.Empty(), nil } self.delLock.RLock() l, err := self.db.LLen(self.key) if err != nil { return nil, err } if _, _, err := convRange(int(from), int(to), int(l), "ledisStreamObj.Read"); err != nil { return nil, err } return &ledisListStream{self.db, self.key, int32(from), int32(from), int32(to), &self.delLock}, nil }
func (self *dirStreamObj) Read(from uint, to uint) (sres stream.Stream, rerr error) { if from == to { return stream.Empty(), nil } self.lock.Lock() defer self.lock.Unlock() l, err := self.slen() if err != nil { return nil, err } if _, _, err := convRange(int(from), int(to), int(l), "dirStreamObj.Read"); err != nil { return nil, err } res := []stream.Event{} file, err := os.Open(self.back.dir + "/" + self.name) if err != nil { return nil, err } defer func() { rerr = errors.List().Add(rerr).Add(file.Close()).Err() if rerr != nil { sres = nil } }() scanner := bufio.NewScanner(file) lineNum := uint(0) for scanner.Scan() { if lineNum >= from && lineNum < to { res = append(res, scanner.Bytes()) } lineNum++ } if err := scanner.Err(); err != nil { return nil, err } return stream.List(res), nil }
func (self nilStreamObj) Read(from uint, to uint) (stream.Stream, error) { if _, _, err := convRange(int(from), int(to), 0, "nilStreamObj.Read"); err != nil { return nil, err } return stream.Empty(), nil }