MCPcopy
hub / github.com/gorilla/websocket / Write

Method Write

compression.go:64–90  ·  view source on GitHub ↗
(p []byte)

Source from the content-addressed store, hash-verified

62}
63
64func (w *truncWriter) Write(p []byte) (int, error) {
65 n := 0
66
67 // fill buffer first for simplicity.
68 if w.n < len(w.p) {
69 n = copy(w.p[w.n:], p)
70 p = p[n:]
71 w.n += n
72 if len(p) == 0 {
73 return n, nil
74 }
75 }
76
77 m := len(p)
78 if m > len(w.p) {
79 m = len(w.p)
80 }
81
82 if nn, err := w.w.Write(w.p[:m]); err != nil {
83 return n + nn, err
84 }
85
86 copy(w.p[:], w.p[m:])
87 copy(w.p[len(w.p)-m:], p[len(p)-m:])
88 nn, err := w.w.Write(p[:len(p)-m])
89 return n + nn, err
90}
91
92type flateWriteWrapper struct {
93 fw *flate.Writer

Callers 2

TestTruncWriterFunction · 0.95
WriteMethod · 0.45

Calls

no outgoing calls

Tested by 1

TestTruncWriterFunction · 0.76