MCPcopy
hub / github.com/wavetermdev/waveterm / streamReadFromFile

Function streamReadFromFile

cmd/wsh/cmd/wshcmd-file-util.go:93–126  ·  view source on GitHub ↗
(ctx context.Context, fileData wshrpc.FileData, writer io.Writer)

Source from the content-addressed store, hash-verified

91}
92
93func streamReadFromFile(ctx context.Context, fileData wshrpc.FileData, writer io.Writer) error {
94 broker := RpcClient.StreamBroker
95 if broker == nil {
96 return fmt.Errorf("stream broker not available")
97 }
98 if fileData.Info == nil {
99 return fmt.Errorf("file info is required")
100 }
101 readerRouteId := RpcClientRouteId
102 if readerRouteId == "" {
103 return fmt.Errorf("no route id available")
104 }
105 conn, err := connparse.ParseURI(fileData.Info.Path)
106 if err != nil {
107 return fmt.Errorf("parsing file path: %w", err)
108 }
109 writerRouteId := wshutil.MakeConnectionRouteId(conn.Host)
110 reader, streamMeta := broker.CreateStreamReader(readerRouteId, writerRouteId, 256*1024)
111 defer reader.Close()
112 go func() {
113 <-ctx.Done()
114 reader.Close()
115 }()
116 data := wshrpc.CommandFileStreamData{
117 Info: fileData.Info,
118 StreamMeta: *streamMeta,
119 }
120 _, err = wshclient.FileStreamCommand(RpcClient, data, nil)
121 if err != nil {
122 return fmt.Errorf("starting file stream: %w", err)
123 }
124 _, err = io.Copy(writer, reader)
125 return err
126}
127
128func fixRelativePaths(path string) (string, error) {
129 conn, err := connparse.ParseURI(path)

Callers 1

fileCatRunFunction · 0.85

Calls 6

ParseURIFunction · 0.92
MakeConnectionRouteIdFunction · 0.92
FileStreamCommandFunction · 0.92
CreateStreamReaderMethod · 0.80
CopyMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected