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

Method Write

pkg/waveapp/streamingresp.go:77–117  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

75}
76
77func (w *StreamingResponseWriter) Write(data []byte) (int, error) {
78 if !w.headerSent {
79 w.WriteHeader(http.StatusOK)
80 }
81
82 originalLen := len(data)
83
84 // If we already have data in the buffer
85 if w.buffer.Len() > 0 {
86 // Fill the buffer up to maxChunkSize
87 spaceInBuffer := maxChunkSize - w.buffer.Len()
88 if spaceInBuffer > 0 {
89 // How much of the new data can fit in the buffer
90 toBuffer := spaceInBuffer
91 if toBuffer > len(data) {
92 toBuffer = len(data)
93 }
94 w.buffer.Write(data[:toBuffer])
95 data = data[toBuffer:] // Advance data slice
96 }
97
98 // If buffer is full, send it
99 if w.buffer.Len() == maxChunkSize {
100 w.sendChunk(w.buffer.Bytes())
101 w.buffer.Reset()
102 }
103 }
104
105 // Send any full chunks from data
106 for len(data) >= maxChunkSize {
107 w.sendChunk(data[:maxChunkSize])
108 data = data[maxChunkSize:]
109 }
110
111 // Buffer any remaining data
112 if len(data) > 0 {
113 w.buffer.Write(data)
114 }
115
116 return originalLen, nil
117}
118
119func (w *StreamingResponseWriter) Close() error {
120 if !w.headerSent {

Callers 1

VDomUrlRequestCommandMethod · 0.95

Calls 5

WriteHeaderMethod · 0.95
sendChunkMethod · 0.95
LenMethod · 0.80
BytesMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected