chan push adds a transformtion layer to an existing channel. The transformation layer is implemented as a command prefix that provides a certain set of methods that are called as needed. Examples include compression/decompression, encryption/decryption, and logging/statistics. A transformation layer is typically implemented either as a namespace ensemble or an object, but can also be implemented as a single procedure whose first agument is the name of a subcommand.
The data arguments to read and write are the raw bytes in the channel, so any transformation that interprets the bytes as text must first decode the bytes, process the data as text, and then reencode the result so that any higher transformation gets raw bytes again. Therefore, transformations that deal in raw bytes are easier to implement.
When a transformation is first pushed onto a channel, initialize is called to get the names of supported methods. Read transformers provide read (mandatory for readers), drain and limit?. Write transformers provide write (mandatory) and flush. Both types must provide finalize, which is called when the channel is closed or the transform layer is removed via chan pop, and may provide clear too.
Normally a channel is attached to exactly one interpreter, and closing that channel results in a call finalize for any transformation layer on the channel. Standard channels, however, are normally attached to each interpreter, and finalize is only called when a standard channel is closed in the last interpreter it is still attached to.