Skip to content
Node: Node streamgithub.com/sahilkhaire/gox/stream

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.Reader

Compare: Node.js · Standard Go · gox

js
// Typical Node stream pattern in Node.js
go
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)

Back to stream package overview

MIT Licensed · Built for Node.js developers moving to Go