// Reader retrieves an io.ReadCloser for the content stored at "path" with a
// given byte offset.
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)
}
507814
func (r *YAMLReader) Read() ([]byte, error) {
	var buffer bytes.Buffer
	for {
		line, err := r.reader.Read()
		if err != nil && err != io.EOF {
			return nil, err
		}

		sep := len([]byte(separator))
		if i := bytes.Index(line, []byte(separator)); i == 0 {
			// We have a potential document terminator
			i += sep
			after := line[i:]
			if len(strings.TrimRightFunc(string(after), unicode.IsSpace)) == 0 {
				if buffer.Len() != 0 {
					return buffer.Bytes(), nil
				}
				if err == io.EOF {
					return nil, err
				}
			}
		}
		if err == io.EOF {
			if buffer.Len() != 0 {
				// If we're at EOF, we have a final, non-terminated line. Return it.
				return buffer.Bytes(), nil
			}
			return nil, err
		}
		buffer.Write(line)
	}
}
271946
func read(path string) ([]byte, error) {
	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer f.Close()

	d, err := ioutil.ReadAll(f)
	if err != nil {
		return nil, err
	}
	return d, nil
}
107805
func (r *ByteReader) Read(b []byte) (n int, err error) {
	if len(b) == 0 {
		return 0, nil
	}
	if r.off >= len(r.buf) {
		return 0, io.EOF
	}
	n = copy(b, r.buf[r.off:])
	r.off += n
	return
}
817522
func (h *HTTPURLReader) Read(url *url.URL) (io.ReadCloser, error) {
	resp, err := h.Get(url.String())
	if err != nil {
		if resp != nil {
			defer resp.Body.Close()
		}
		return nil, err
	}
	if resp.StatusCode == 200 || resp.StatusCode == 201 {
		return resp.Body, nil
	}
	return nil, s2ierr.NewDownloadError(url.String(), resp.StatusCode)
}
446895
func (r *ReverseReader) Read(p []byte) (n int, err error) {
	//fmt.Printf("Offset %d\n", r.offset)
	//fmt.Printf("Reading %d bytes\n", len(p))
	switch {
	case r.offset <= 0:
		return 0, io.EOF
	case r.offset-int64(len(p)) <= 0:
		r.rs.Seek(0, os.SEEK_SET)
		n, err = r.rs.Read(p[:r.offset])
		r.rs.Seek(0, os.SEEK_SET)
		r.offset = 0
		return n, nil
	default:
		r.offset -= int64(len(p))
		r.rs.Seek(r.offset, os.SEEK_SET)
		n, err = r.rs.Read(p)
		r.rs.Seek(r.offset, os.SEEK_SET)
		return
	}
}
816195
func (e *Elasticsearch) Reader() (client.Reader, error) {
	return nil, adaptor.ErrFuncNotSupported{Name: "Reader()", Func: "elasticsearch"}
}
320813
func (s nopTranslateStore) Reader(ctx context.Context, off int64) (io.ReadCloser, error) {
	return ioutil.NopCloser(bytes.NewReader(nil)), nil
}
685290
func (r *Reader) Read(p []byte) (int, error) {
	// If we haven't drawn before, initialize the progress bar
	if r.lastDraw.IsZero() {
		r.initProgress()
	}

	// Read from the underlying source
	n, err := r.Reader.Read(p)

	// Always increment the progress even if there was an error
	r.progress += int64(n)

	// If we don't have any errors, then draw the progress. If we are
	// at the end of the data, then finish the progress.
	if err == nil {
		// Only draw if we read data or we've never read data before (to
		// initialize the progress bar).
		if n > 0 {
			r.drawProgress()
		}
	}
	if err == io.EOF {
		r.finishProgress()
	}

	return n, err
}
926016
func (r *Reader) Read(p []byte) (n int, err error) {
	p = p[:r.Limit(len(p), r.limit, r.block)]
	if len(p) > 0 {
		n, err = r.IO(r.Reader.Read(p))
	}
	return
}
1246714
func (r *Reader) Read() ([]byte, error) {
	r.Lock()
	defer r.Unlock()

	if _, err := io.ReadFull(r.r, r.buff[:]); err != nil {
		return nil, err
	}

	length := int64(binary.BigEndian.Uint32(r.buff[:]))
	if length < _fastPathFrameSize {
		return r.readFastPath(length)
	}

	var buff bytes.Buffer
	_, err := io.CopyN(&buff, r.r, length)
	if err != nil {
		return nil, err
	}

	return buff.Bytes(), nil
}
225786
func (ch *Chunk) Read(p []byte) (n int, err error) {
	if ch == nil || ch.R == nil {
		return 0, errors.New("nil chunk/reader pointer")
	}
	n, err = ch.R.Read(p)
	ch.Pos += n
	return n, err
}
465247
func (*ImageReader) Read(url *url.URL) (io.ReadCloser, error) {
	return nil, s2ierr.NewScriptsInsideImageError(url.String())
}
1233957
func (r *Reader) Read(p []byte) (n int, err error) {
	// Check context
	if err = r.ctx.Err(); err != nil {
		return
	}

	// Read
	return r.reader.Read(p)
}
937127
func (v ByteView) Reader() io.ReadSeeker {
	if v.b != nil {
		return bytes.NewReader(v.b)
	}
	return strings.NewReader(v.s)
}
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
}
584810
func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
	headers := make(swift.Headers)
	headers["Range"] = "bytes=" + strconv.FormatInt(offset, 10) + "-"

	waitingTime := readAfterWriteWait
	endTime := time.Now().Add(readAfterWriteTimeout)

	for {
		file, headers, err := d.Conn.ObjectOpen(d.Container, d.swiftPath(path), false, headers)
		if err != nil {
			if err == swift.ObjectNotFound {
				return nil, storagedriver.PathNotFoundError{Path: path}
			}
			if swiftErr, ok := err.(*swift.Error); ok && swiftErr.StatusCode == http.StatusRequestedRangeNotSatisfiable {
				return ioutil.NopCloser(bytes.NewReader(nil)), nil
			}
			return file, err
		}

		//if this is a DLO and it is clear that segments are still missing,
		//wait until they show up
		_, isDLO := headers["X-Object-Manifest"]
		size, err := file.Length()
		if err != nil {
			return file, err
		}
		if isDLO && size == 0 {
			if time.Now().Add(waitingTime).After(endTime) {
				return nil, fmt.Errorf("timeout expired while waiting for segments of %s to show up", path)
			}
			time.Sleep(waitingTime)
			waitingTime *= 2
			continue
		}

		//if not, then this reader will be fine
		return file, nil
	}
}