(ctx context.Context, readCh <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData])
| 121 | } |
| 122 | |
| 123 | func ReadStreamToFileData(ctx context.Context, readCh <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData]) (*wshrpc.FileData, error) { |
| 124 | var fileData *wshrpc.FileData |
| 125 | var dataBuf bytes.Buffer |
| 126 | var entries []*wshrpc.FileInfo |
| 127 | err := ReadFileStream(ctx, readCh, func(finfo wshrpc.FileInfo) { |
| 128 | fileData = &wshrpc.FileData{ |
| 129 | Info: &finfo, |
| 130 | } |
| 131 | }, func(fileEntries []*wshrpc.FileInfo) error { |
| 132 | entries = append(entries, fileEntries...) |
| 133 | return nil |
| 134 | }, func(data io.Reader) error { |
| 135 | if _, err := io.Copy(&dataBuf, data); err != nil { |
| 136 | return err |
| 137 | } |
| 138 | return nil |
| 139 | }) |
| 140 | if err != nil { |
| 141 | return nil, err |
| 142 | } |
| 143 | if fileData == nil { |
| 144 | return nil, fmt.Errorf("stream file protocol error, no file info") |
| 145 | } |
| 146 | if !fileData.Info.IsDir { |
| 147 | fileData.Data64 = base64.StdEncoding.EncodeToString(dataBuf.Bytes()) |
| 148 | } else { |
| 149 | fileData.Entries = entries |
| 150 | } |
| 151 | return fileData, nil |
| 152 | } |
nothing calls this directly
no test coverage detected