hashicorp / hashicorp/hcl

Decoder from io.Reader

Open
#523 2 comments 0 reactions 0 assignees View on GitHub
enhancement syntax/json syntax/native v2
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

Hi, I noticed that this package implements a Decode function that decodes from `[]byte` I think it would be good if there was a function like in the std `encoding` packages with a signature like this: `hcl.NewDecoder(io.Reader) *hcl.Decoder`.

This would align with the established pattern of the `encoding/json` and other packages such as `gopkg.in/yaml`.

So that you could do something like this

```go
dec := hcl.NewDecoder(os.stdin)
var data any
for {
if err := dec.Decode(&data); err == io.EOF {
break
} else if err != nil {
panic(err)
}
}
```

I think if it reads from `[]byte` it's more like `Unmarshal` than `Decode`.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the existing Decode function and examining how it consumes []byte. Compare its behavior with Go's encoding/json Decoder and the proposed io.Reader loop, then determine what tests would demonstrate repeated decoding and io.EOF. Done means the package exposes the requested reader-based decoder behavior without breaking the existing API.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.