Transform
Overview
Transform returns a Reader that applies fn to each chunk from reader.
Part of the stream package — Node.js analog: Node stream.
Signature
go
func Transform(reader io.Reader, fn func([]byte) ([]byte, error)) io.ReaderCompare: Node.js · Standard Go · gox
js
// Typical Node stream pattern in Node.jsgo
io.Copy(dst, src)
// or io.ReadAll(r)go
import "github.com/sahilkhaire/gox/stream"
out := stream.Transform(r, func(p []byte) ([]byte, error) { return p, nil })Example
go
import "github.com/sahilkhaire/gox/stream"
out := stream.Transform(r, func(p []byte) ([]byte, error) { return p, nil })Tips
Import github.com/sahilkhaire/gox/stream and call Transform directly. See the comparison below for the standard library equivalent.
Standard library alternative
Use the standard library directly:
go
io.Copy(dst, src)
// or io.ReadAll(r)