(ctx context.Context, fileData wshrpc.FileData, writer io.Writer)
| 91 | } |
| 92 | |
| 93 | func 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 | |
| 128 | func fixRelativePaths(path string) (string, error) { |
| 129 | conn, err := connparse.ParseURI(path) |
no test coverage detected