You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.0 KiB

  1. package filer2
  2. import (
  3. "io"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. "github.com/chrislusf/seaweedfs/weed/wdclient"
  8. )
  9. func StreamContent(masterClient *wdclient.MasterClient, w io.Writer, chunks []*filer_pb.FileChunk, offset int64, size int) error {
  10. chunkViews := ViewFromChunks(chunks, offset, size)
  11. fileId2Url := make(map[string]string)
  12. for _, chunkView := range chunkViews {
  13. urlString, err := masterClient.LookupFileId(chunkView.FileId)
  14. if err != nil {
  15. glog.V(1).Infof("operation LookupFileId %s failed, err: %v", chunkView.FileId, err)
  16. return err
  17. }
  18. fileId2Url[chunkView.FileId] = urlString
  19. }
  20. for _, chunkView := range chunkViews {
  21. urlString := fileId2Url[chunkView.FileId]
  22. _, err := util.ReadUrlAsStream(urlString, chunkView.Offset, int(chunkView.Size), func(data []byte) {
  23. w.Write(data)
  24. })
  25. if err != nil {
  26. glog.V(1).Infof("read %s failed, err: %v", chunkView.FileId, err)
  27. return err
  28. }
  29. }
  30. return nil
  31. }