MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / ReadStreamToFileData

Function ReadStreamToFileData

pkg/remote/fileshare/fsutil/fsutil.go:123–152  ·  view source on GitHub ↗
(ctx context.Context, readCh <-chan wshrpc.RespOrErrorUnion[wshrpc.FileData])

Source from the content-addressed store, hash-verified

121}
122
123func 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}

Callers

nothing calls this directly

Calls 3

ReadFileStreamFunction · 0.85
CopyMethod · 0.80
BytesMethod · 0.80

Tested by

no test coverage detected