Skip to content
Node: Buffer.from(data)github.com/sahilkhaire/gox/buffer

Buffer.From

Overview

From allocates a copy of data (Buffer.from).

If you are coming from Node.js, the closest pattern is Buffer.from(data).

Method on Buffer — call it on a value of that type after constructing or receiving one from a constructor.

Signature

go
func From(data []byte) Buffer

Compare: Node.js · Standard Go · gox

js
Buffer.from([1, 2, 3]);
go
b := append([]byte(nil), parts...)
go
import "github.com/sahilkhaire/gox/buffer"

b := buffer.From([]byte{1, 2, 3})

Example

go
import "github.com/sahilkhaire/gox/buffer"

b := buffer.From([]byte{1, 2, 3})

Tips

Obtain a Buffer value first (see constructors on the package overview), then call From.

Standard library alternative

Use the standard library directly:

go
b := append([]byte(nil), parts...)

Back to buffer package overview

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