Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Array of Streams support #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,15 +788,28 @@ func (e *errorReadCloser) Close() error {
}

// Reader returns the data contained in the stream v.
// If v.Kind() != Stream, Reader returns a ReadCloser that
// responds to all reads with a ``stream not present'' error.
// If v.Kind() is not a stream or an array of streams,
// Reader returns a ReadCloser that responds to all reads
// with a ``stream not present'' error.
func (v Value) Reader() io.ReadCloser {
x, ok := v.data.(stream)
if !ok {
if x, ok := v.data.(array); ok {
r := make([]io.Reader, len(x))
for i, s := range x {
r[i] = v.r.resolve(v.ptr, s).Reader()
}
return ioutil.NopCloser(io.MultiReader(r...))
}
return &errorReadCloser{fmt.Errorf("stream not present")}
}
var rd io.Reader
rd = io.NewSectionReader(v.r.f, x.offset, v.Key("Length").Int64())
l := v.Key("Length").Int64()
rd = io.NewSectionReader(v.r.f, x.offset, l)
if l == 0 {
// if Length is zero, skip filter processing
return ioutil.NopCloser(rd)
}
if v.r.key != nil {
rd = decryptStream(v.r.key, v.r.useAES, x.ptr, rd)
}
Expand Down