aboutsummaryrefslogtreecommitdiff
path: root/protocol/sideband64k/chunk_writer.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-25 16:22:03 +0000
committerGravatar Runxi Yu2026-03-25 16:22:03 +0000
commit311edcd50f3a84f4b860bde3cb887451d74eaa11 (patch)
treebe7aa5e9a51e636358f33b1c90637b5024b70dc3 /protocol/sideband64k/chunk_writer.go
parentREADME: Split off contrib, benchmarks, remove history for now I guess, etc. (diff)
signatureNo signature
network/protocol: Rename from protocol v0.1.110
Diffstat (limited to 'protocol/sideband64k/chunk_writer.go')
-rw-r--r--protocol/sideband64k/chunk_writer.go64
1 files changed, 0 insertions, 64 deletions
diff --git a/protocol/sideband64k/chunk_writer.go b/protocol/sideband64k/chunk_writer.go
deleted file mode 100644
index f95f75d8..00000000
--- a/protocol/sideband64k/chunk_writer.go
+++ /dev/null
@@ -1,64 +0,0 @@
-package sideband64k
-
-import "io"
-
-// ChunkWriter packetizes arbitrary stream bytes into side-band-64k data frames
-// for one fixed band.
-//
-// It never writes control packets automatically.
-type ChunkWriter struct {
- enc *Encoder
- band Band
-}
-
-// NewChunkWriter creates a chunking adapter over enc for one band.
-func NewChunkWriter(enc *Encoder, band Band) *ChunkWriter {
- return &ChunkWriter{enc: enc, band: band}
-}
-
-// Write splits p into sideband frames not larger than enc's maxData.
-func (cw *ChunkWriter) Write(p []byte) (int, error) {
- total := 0
- maxData := cw.enc.effectiveMaxData()
-
- for len(p) > 0 {
- n := min(len(p), maxData)
-
- err := cw.enc.WriteBand(cw.band, p[:n])
- if err != nil {
- return total, err
- }
-
- total += n
- p = p[n:]
- }
-
- return total, nil
-}
-
-// ReadFrom reads from r and writes sideband frames to the encoder.
-func (cw *ChunkWriter) ReadFrom(r io.Reader) (int64, error) {
- buf := make([]byte, cw.enc.effectiveMaxData())
-
- var total int64
-
- for {
- n, err := r.Read(buf)
- if n > 0 {
- werr := cw.enc.WriteBand(cw.band, buf[:n])
- if werr != nil {
- return total, werr
- }
-
- total += int64(n)
- }
-
- if err != nil {
- if err == io.EOF {
- return total, nil
- }
-
- return total, err
- }
- }
-}