Exemple #1
0
// GetReader returns an io.ReadCloser for the Blob with the given name of
// type t at offset and length. If length is 0, the reader reads until EOF.
func (b *Local) GetReader(t backend.Type, name string, offset, length uint) (io.ReadCloser, error) {
	f, err := os.Open(filename(b.p, t, name))
	if err != nil {
		return nil, err
	}

	_, err = f.Seek(int64(offset), 0)
	if err != nil {
		return nil, err
	}

	if length == 0 {
		return f, nil
	}

	return backend.LimitReadCloser(f, int64(length)), nil
}
Exemple #2
0
// GetReader returns an io.ReadCloser for the Blob with the given name of
// type t at offset and length. If length is 0, the reader reads until EOF.
func (r *SFTP) GetReader(t backend.Type, name string, offset, length uint) (io.ReadCloser, error) {
	f, err := r.c.Open(r.filename(t, name))
	if err != nil {
		return nil, err
	}

	if offset > 0 {
		_, err = f.Seek(int64(offset), 0)
		if err != nil {
			return nil, err
		}
	}

	if length == 0 {
		return f, nil
	}

	return backend.LimitReadCloser(f, int64(length)), nil
}
Exemple #3
0
// GetReader returns an io.ReadCloser for the Blob with the given name of
// type t at offset and length. If length is 0, the reader reads until EOF.
func (be *S3Backend) GetReader(t backend.Type, name string, offset, length uint) (io.ReadCloser, error) {
	rc, err := be.Get(t, name)
	if err != nil {
		return nil, err
	}

	n, errc := io.CopyN(ioutil.Discard, rc, int64(offset))
	if errc != nil {
		return nil, errc
	} else if n != int64(offset) {
		return nil, fmt.Errorf("less bytes read than expected, read: %d, expected: %d", n, offset)
	}

	if length == 0 {
		return rc, nil
	}

	return backend.LimitReadCloser(rc, int64(length)), nil
}
Exemple #4
0
// GetReader returns an io.ReadCloser for the Blob with the given name of
// type t at offset and length. If length is 0, the reader reads until EOF.
func (b *Local) GetReader(t backend.Type, name string, offset, length uint) (io.ReadCloser, error) {
	f, err := os.Open(filename(b.p, t, name))
	if err != nil {
		return nil, err
	}

	b.mu.Lock()
	open, _ := b.open[filename(b.p, t, name)]
	b.open[filename(b.p, t, name)] = append(open, f)
	b.mu.Unlock()

	_, err = f.Seek(int64(offset), 0)
	if err != nil {
		return nil, err
	}

	if length == 0 {
		return f, nil
	}

	return backend.LimitReadCloser(f, int64(length)), nil
}
Exemple #5
0
// GetReader returns an io.ReadCloser for the Blob with the given name of
// type t at offset and length. If length is 0, the reader reads until EOF.
func (be *S3Backend) GetReader(t backend.Type, name string, offset, length uint) (io.ReadCloser, error) {
	debug.Log("s3.GetReader", "%v %v, offset %v len %v", t, name, offset, length)
	path := s3path(t, name)
	obj, err := be.client.GetObject(be.bucketname, path)
	if err != nil {
		debug.Log("s3.GetReader", "  err %v", err)
		return nil, err
	}

	if offset > 0 {
		_, err = obj.Seek(int64(offset), 0)
		if err != nil {
			return nil, err
		}
	}

	if length == 0 {
		return obj, nil
	}

	return backend.LimitReadCloser(obj, int64(length)), nil
}