diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-10-08 23:19:42 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-10-08 23:19:42 -0700 |
| commit | 6e1f936efd5b28ef15c2f3b388f07c34bbdb527b (patch) | |
| tree | 8cc328751d21489cd27d480b0bfa0665570714ea /weed/filer/stream.go | |
| parent | b2ee5873fbec831a480bdf62be20c649a09b49ba (diff) | |
| download | seaweedfs-6e1f936efd5b28ef15c2f3b388f07c34bbdb527b.tar.xz seaweedfs-6e1f936efd5b28ef15c2f3b388f07c34bbdb527b.zip | |
refactoring
Diffstat (limited to 'weed/filer/stream.go')
| -rw-r--r-- | weed/filer/stream.go | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/weed/filer/stream.go b/weed/filer/stream.go index d98229379..e1be18f69 100644 --- a/weed/filer/stream.go +++ b/weed/filer/stream.go @@ -32,18 +32,13 @@ func StreamContent(masterClient *wdclient.MasterClient, w io.Writer, chunks []*f for _, chunkView := range chunkViews { urlStrings := fileId2Url[chunkView.FileId] - for _, urlString := range urlStrings { - err := util.ReadUrlAsStream(urlString, chunkView.CipherKey, chunkView.IsGzipped, chunkView.IsFullChunk(), chunkView.Offset, int(chunkView.Size), func(data []byte) { - w.Write(data) - }) - if err != nil { - // data already written to w would be wrong - // but usually there are nothing written if fails to read - glog.V(1).Infof("read %s failed, err: %v", chunkView.FileId, err) - } else { - break - } + + data, err := fetchChunkData(urlStrings, chunkView.CipherKey, chunkView.IsGzipped, chunkView.IsFullChunk(), chunkView.Offset, int(chunkView.Size)) + if err == nil { + return err } + w.Write(data) + } return nil @@ -68,17 +63,12 @@ func ReadAll(masterClient *wdclient.MasterClient, chunks []*filer_pb.FileChunk) glog.V(1).Infof("operation LookupFileId %s failed, err: %v", chunkView.FileId, err) return nil, err } - for _, urlString := range urlStrings { - err = util.ReadUrlAsStream(urlString, chunkView.CipherKey, chunkView.IsGzipped, chunkView.IsFullChunk(), chunkView.Offset, int(chunkView.Size), func(data []byte) { - buffer.Write(data) - }) - if err != nil { - glog.V(1).Infof("read %s failed, err: %v", chunkView.FileId, err) - buffer.Reset() - } else { - break - } + + data, err := fetchChunkData(urlStrings, chunkView.CipherKey, chunkView.IsGzipped, chunkView.IsFullChunk(), chunkView.Offset, int(chunkView.Size)) + if err != nil { + return nil, err } + buffer.Write(data) } return buffer.Bytes(), nil } |
