// Reader wraps Reader of underlying storage driver.
15404
func (base *Base) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
	ctx, done := dcontext.WithTrace(ctx)
	defer done("%s.Reader(%q, %d)", base.Name(), path, offset)

	if offset < 0 {
		return nil, storagedriver.InvalidOffsetError{Path: path, Offset: offset, DriverName: base.StorageDriver.Name()}
	}

	if !storagedriver.PathRegexp.MatchString(path) {
		return nil, storagedriver.InvalidPathError{Path: path, DriverName: base.StorageDriver.Name()}
	}

	rc, e := base.StorageDriver.Reader(ctx, path, offset)
	return rc, base.setDriverName(e)
}
34613
func (m *M) Reader(mediatype string, r io.Reader) io.Reader {
	pr, pw := io.Pipe()
	go func() {
		if err := m.Minify(mediatype, pw, r); err != nil {
			pw.CloseWithError(err)
		} else {
			pw.Close()
		}
	}()
	return pr
}
880049
func (r *Reader) Read(b []byte) (n int, err error) {
	for {
		// If there's no data in the buffer, we'll grab the next record
		// and set the internal buffer to point to the data in that
		// record. When all data from buf is read, Done() will be called
		// on the record.
		if len(r.buf) == 0 {
			select {
			case record, ok := <-r.records:
				if !ok {
					// Channel is closed, return io.EOF.
					err = io.EOF
					return
				}

				r.buf = record.Data()
				r.done = record.Done
			default:
				// By convention, Read should return rather than wait
				// for data to become available. If no data is available
				// at this time, we'll return what we've copied
				// so far.
				return
			}
		}

		n += r.copy(b[n:])
		if n == len(b) {
			return
		}
	}

	return
}
822178
func (o *FileSystemSaver) Read() (store uuid.Store, err error) {
	store = uuid.Store{}
	_, err = os.Stat(o.Path);
	if err != nil {
		if os.IsNotExist(err) {
			dir, file := path.Split(o.Path)
			if dir == "" || dir == "/" {
				dir = os.TempDir()
			}
			o.Path = path.Join(dir, file)

			err = os.MkdirAll(dir, os.ModeDir|0700)
			if err == nil {
				// If new encode blank store
				goto open
			}
		}
		goto failed
	}

	open:
	err = o.openAndDo(o.decode, &store)
	if err == nil {
		o.Println("file system saver created", o.Path)
		return
	}

	failed:
	o.Println("file system saver read error - will autogenerate", err)
	return
}
814923
func (f *DatastoreFile) Read(b []byte) (int, error) {
	if f.offset.read != f.offset.seek {
		// A Seek() call changed the offset, we need to issue a new GET
		_ = f.Close()

		f.offset.read = f.offset.seek
	} else if f.buf != nil {
		// f.buf + f behaves like an io.MultiReader
		n, err := f.buf.Read(b)
		if err == io.EOF {
			f.buf = nil // buffer has been drained
		}
		if n > 0 {
			return n, nil
		}
	}

	body, err := f.get()
	if err != nil {
		return 0, err
	}

	n, err := body.Read(b)

	f.offset.read += int64(n)
	f.offset.seek += int64(n)

	return n, err
}
132510
func (sf *SubtitleFile) Reader() (r io.ReadCloser, err error) {
	if sf.reader != nil {
		return sf.reader, err
	}

	dec := base64.NewDecoder(base64.StdEncoding, strings.NewReader(sf.Data))
	gzReader, err := gzip.NewReader(dec)
	if err != nil {
		return nil, err
	}

	if sf.Encoding == nil {
		sf.reader = gzReader
	} else {
		sf.reader = newCloseableReader(
			sf.Encoding.NewDecoder().Reader(gzReader),
			gzReader.Close,
		)
	}

	return sf.reader, nil
}
604020
func (r *Reader) Read(p []byte) (n int, err error) {
	if len(p) == 0 {
		return 0, nil
	}

	if r.buf == nil {
		if r.err != nil {
			return 0, r.readErr()
		}

		return r.rd.Read(p)
	}

	// copy as much as we can
	n = copy(p, r.buf)
	r.buf = nilIfEmpty(r.buf[n:])
	return n, nil
}
975893
func (s *EncryptedStorageProvider) Reader(path ...string) (decryptReader io.ReadCloser, err error) {
	var unEncryptedReader io.ReadCloser
	stream := s.getStream()

	if unEncryptedReader, err = s.wrappedStorageProvider.Reader(path...); err == nil {

		decryptReader = &StreamReadCloser{
			StreamReader: cipher.StreamReader{S: stream, R: unEncryptedReader},
			Closer:       unEncryptedReader,
		}
	}
	return
}
672596
func (gs *impl) Reader(c context.Context, path string, gen int64) (Reader, error) {
	logging.Infof(c, "gs: Reader(path=%q, gen=%d)", path, gen)
	if err := gs.init(); err != nil {
		return nil, err
	}

	// Fetch the object metadata, including its size and the generation number
	// (which is useful when 'gen' is <= 0).
	call := gs.srv.Objects.Get(SplitPath(path)).Context(c)
	if gen > 0 {
		call.Generation(gen)
	}
	var obj *storage.Object
	err := withRetry(c, func() (err error) { obj, err = call.Do(); return })
	if err != nil {
		return nil, errors.Annotate(err, "failed to grab the object size and generation").Err()
	}

	// Carry on reading from the resolved generation. That way we are not
	// concerned with concurrent changes that may be happening to the file while
	// we are reading it.
	return &readerImpl{c, gs, path, int64(obj.Size), obj.Generation}, nil
}
87121
func (r *cachingReadCloser) Read(p []byte) (n int, err error) {
	n, err = r.R.Read(p)
	r.buf.Write(p[:n])
	if err == io.EOF {
		r.OnEOF(bytes.NewReader(r.buf.Bytes()))
	}
	return n, err
}
879966
func Read(disk io.Reader) (*MBR, error) {
	var this *MBR = &MBR{}
	this.bytes = make([]byte, mbrSize)
	_, err := disk.Read(this.bytes)
	if err != nil {
		return this, err
	}

	return this, this.Check()
}
1124538
func (s *Server) reader(ctx context.Context) {
	for {
		v, _, err := s.conn.Read()
		if err != nil {
			return
		}

		h := header(v)
		if !h.isValid() || h.op() != opRequest {
			continue
		}
		xid := h.xid()

		// Fan out the packet to a handler goroutine.
		//
		// Use a consistent handler for a given xid, so that
		// packets from a particular client are processed
		// in order.
		ch := s.handlers[int(xid)%len(s.handlers)]
		select {
		case <-ctx.Done():
			return
		case ch <- h:
		default:
			// drop the packet
		}
	}
}
1253079
func (r *CountReader) Read(b []byte) (n int, err error) {
	if n, err = r.R.Read(b); n > 0 {
		r.N += n
	}
	return
}
1073862
func StorageReader(storage StorageAPI, volume, path string, offset int64) io.Reader {
	return &storageReader{storage, volume, path, offset}
}
237970
func (f *StandaloneFile) Reader() (filesystem.Reader, error) {
	return f.filespace.Reader(f.path)
}
554370
func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
	d.mutex.RLock()
	defer d.mutex.RUnlock()

	return d.reader(ctx, path, offset)
}
819331
func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
	headers := make(http.Header)
	headers.Add("Range", "bytes="+strconv.FormatInt(offset, 10)+"-")

	resp, err := d.Bucket.GetResponseWithHeaders(d.ossPath(path), headers)
	if err != nil {
		return nil, parseError(path, err)
	}

	// Due to Aliyun OSS API, status 200 and whole object will be return instead of an
	// InvalidRange error when range is invalid.
	//
	// OSS sever will always return http.StatusPartialContent if range is acceptable.
	if resp.StatusCode != http.StatusPartialContent {
		resp.Body.Close()
		return ioutil.NopCloser(bytes.NewReader(nil)), nil
	}

	return resp.Body, nil
}