MCPcopy
hub / github.com/nats-io/nats.go / Read

Method Read

ws.go:113–131  ·  view source on GitHub ↗
(dst []byte)

Source from the content-addressed store, hash-verified

111}
112
113func (d *wsDecompressor) Read(dst []byte) (int, error) {
114 if len(dst) == 0 {
115 return 0, nil
116 }
117 if len(d.bufs) == 0 {
118 return 0, io.EOF
119 }
120 copied := 0
121 rem := len(dst)
122 for buf := d.bufs[0]; buf != nil && rem > 0; {
123 n := min(len(buf[d.off:]), rem)
124 copy(dst[copied:], buf[d.off:d.off+n])
125 copied += n
126 rem -= n
127 d.off += n
128 buf = d.nextBuf()
129 }
130 return copied, nil
131}
132
133func (d *wsDecompressor) nextBuf() []byte {
134 // We still have remaining data in the first buffer

Callers 3

TestWSDecompressorFunction · 0.95
ReadMethod · 0.45
wsGetFunction · 0.45

Calls 1

nextBufMethod · 0.95

Tested by 1

TestWSDecompressorFunction · 0.76