Skip to content
Node: fs.readFile(path)github.com/sahilkhaire/gox/fs

ReadFile

Overview

Reads an entire file with context cancellation — fs.promises.readFile with Go context support.

If you are coming from Node.js, the closest pattern is fs.readFile(path).

Signature

go
func ReadFile(ctx context.Context, path string) ([]byte, error)

Compare: Node.js · Standard Go · gox

js
const data = await fs.promises.readFile('file.txt');
go
data, err := os.ReadFile("file.txt")
go
import "github.com/sahilkhaire/gox/fs"

data, err := fs.ReadFile(ctx, "file.txt")

Example

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

data, err := fs.ReadFile(ctx, "file.txt")

Tips

Prefer context-aware I/O so requests can cancel long reads.

Standard library alternative

Use the standard library directly:

go
data, err := os.ReadFile("file.txt")

Back to fs package overview

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