Help us shape the future of Go! Take the 2026 Go Developer Survey

stdcopy

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package stdcopy implements the Docker multiplexed-stream protocol used by the attach, exec and logs endpoints.

The wire format (when Tty=false on the server) is:

+----------+---------+---------+---------+---------+
|  1 byte  | 3 bytes |      4 bytes (BE)         |
|  STREAM  | padding | FRAME SIZE (uint32, big)  |
+----------+---------+---------+---------+---------+
| FRAME PAYLOAD (FRAMEsIZE bytes)                 |
+--------------------------------------------------+

STREAM values: 0 = stdin, 1 = stdout, 2 = stderr.

When Tty=true, the server sends raw bytes without framing (the PTY already merges stdout+stderr).

This file is the Go counterpart of github.com/docker/cli/pkg/stdcopy and matches Docker Engine v25+ framing exactly.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHeader = errors.New("stdcopy: invalid frame header")

ErrInvalidHeader is returned when the 8-byte header is malformed.

Functions

func StdCopy

func StdCopy(dstOut, dstErr io.Writer, src io.Reader) (written int64, err error)

StdCopy is the equivalent of github.com/docker/cli/pkg/stdcopy.StdCopy: demultiplexes r into stdout and stderr writers. A non-blocking read of stdout is forwarded to dstOut; stderr to dstErr. Stdin frames on the read side are also forwarded to dstOut (legacy Docker behavior).

Loop terminates cleanly on EOF. Any frame >2 (protocol extension) is silently skipped.

func StdCopySingleReader

func StdCopySingleReader(dst io.Writer, src io.Reader) (int64, error)

StdCopySingleReader is like StdCopy but for the case when the source is an unframed raw stream (Tty=true). It just copies src to dst.

func WriteFrame

func WriteFrame(w io.Writer, t StreamType, payload []byte) (int, error)

WriteFrame writes a single frame to w: 8-byte header + payload.

Types

type StreamType

type StreamType byte

StreamType identifies the channel in a multiplexed frame.

const (
	StreamStdin  StreamType = 0
	StreamStdout StreamType = 1
	StreamStderr StreamType = 2
)

func ReadFrame

func ReadFrame(r io.Reader) (StreamType, []byte, error)

ReadFrame reads exactly one frame from r.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL