Skip to content

Commit

Permalink
Merge pull request #32 from mvdan/parse-reader
Browse files Browse the repository at this point in the history
allow parsing from an io.Reader
  • Loading branch information
andreynering authored Oct 3, 2019
2 parents 56ffdb0 + 0ea8f6a commit 381eddb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions editorconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package editorconfig
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -67,8 +68,15 @@ type Editorconfig struct {
}

// ParseBytes parses from a slice of bytes.
//
// Deprecated: use Parse instead.
func ParseBytes(data []byte) (*Editorconfig, error) {
iniFile, err := ini.Load(data)
return Parse(bytes.NewReader(data))
}

// Parse parses from a reader.
func Parse(r io.Reader) (*Editorconfig, error) {
iniFile, err := ini.Load(ioutil.NopCloser(r))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -105,13 +113,13 @@ func ParseBytes(data []byte) (*Editorconfig, error) {
}

// ParseFile parses from a file.
func ParseFile(f string) (*Editorconfig, error) {
data, err := ioutil.ReadFile(f)
func ParseFile(path string) (*Editorconfig, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}

return ParseBytes(data)
defer f.Close()
return Parse(f)
}

// normalize fixes some values to their lowercaes value
Expand Down

0 comments on commit 381eddb

Please sign in to comment.