MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / runReadFile

Function runReadFile

cmd/wsh/cmd/wshcmd-readfile.go:29–72  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

27}
28
29func runReadFile(cmd *cobra.Command, args []string) {
30 fullORef, err := resolveBlockArg()
31 if err != nil {
32 WriteStderr("[error] %v\n", err)
33 return
34 }
35
36 broker := RpcClient.StreamBroker
37 if broker == nil {
38 WriteStderr("[error] stream broker not available\n")
39 return
40 }
41
42 readerRouteId, err := wshclient.ControlGetRouteIdCommand(RpcClient, &wshrpc.RpcOpts{Route: wshutil.ControlRoute})
43 if err != nil {
44 WriteStderr("[error] getting route id: %v\n", err)
45 return
46 }
47 if readerRouteId == "" {
48 WriteStderr("[error] no route to receive data\n")
49 return
50 }
51 writerRouteId := ""
52 reader, streamMeta := broker.CreateStreamReader(readerRouteId, writerRouteId, 64*1024)
53 defer reader.Close()
54
55 data := wshrpc.CommandWaveFileReadStreamData{
56 ZoneId: fullORef.OID,
57 Name: args[0],
58 StreamMeta: *streamMeta,
59 }
60
61 _, err = wshclient.WaveFileReadStreamCommand(RpcClient, data, nil)
62 if err != nil {
63 WriteStderr("[error] starting stream read: %v\n", err)
64 return
65 }
66
67 _, err = io.Copy(os.Stdout, reader)
68 if err != nil {
69 WriteStderr("[error] reading stream: %v\n", err)
70 return
71 }
72}

Callers

nothing calls this directly

Calls 7

ControlGetRouteIdCommandFunction · 0.92
resolveBlockArgFunction · 0.85
WriteStderrFunction · 0.85
CreateStreamReaderMethod · 0.80
CopyMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected