Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
back ported Find and FindString
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Oct 27, 2018
1 parent 9bddd28 commit 67d3450
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
35 changes: 25 additions & 10 deletions box.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,42 @@ func (b Box) AddBytes(path string, t []byte) {
b.data[path] = t
}

// String of the file asked for or an empty string.
// String is deprecated. Use Find instead
func (b Box) String(name string) string {
return string(b.Bytes(name))
oncer.Deprecate(0, "github.com/gobuffalo/packr#Box.String", "Use github.com/gobuffalo/packr#Box.FindString instead.")
bb, _ := b.FindString(name)
return bb
}

// MustString returns either the string of the requested
// file or an error if it can not be found.
// MustString is deprecated. Use FindString instead
func (b Box) MustString(name string) (string, error) {
bb, err := b.MustBytes(name)
return string(bb), err
oncer.Deprecate(0, "github.com/gobuffalo/packr#Box.MustString", "Use github.com/gobuffalo/packr#Box.FindString instead.")
return b.FindString(name)
}

// Bytes of the file asked for or an empty byte slice.
// Bytes is deprecated. Use Find instead
func (b Box) Bytes(name string) []byte {
bb, _ := b.MustBytes(name)
oncer.Deprecate(0, "github.com/gobuffalo/packr#Box.Bytes", "Use github.com/gobuffalo/packr#Box.Find instead.")
bb, _ := b.Find(name)
return bb
}

// MustBytes returns either the byte slice of the requested
// file or an error if it can not be found.
// Bytes is deprecated. Use Find instead
func (b Box) MustBytes(name string) ([]byte, error) {
oncer.Deprecate(0, "github.com/gobuffalo/packr#Box.MustBytes", "Use github.com/gobuffalo/packr#Box.Find instead.")
return b.Find(name)
}

// FindString returns either the string of the requested
// file or an error if it can not be found.
func (b Box) FindString(name string) (string, error) {
bb, err := b.Find(name)
return string(bb), err
}

// Find returns either the byte slice of the requested
// file or an error if it can not be found.
func (b Box) Find(name string) ([]byte, error) {
f, err := b.find(name)
if err == nil {
bb := &bytes.Buffer{}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/markbates/oncer v0.0.0-20181014194634-05fccaae8fc4
github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.3 // indirect
github.com/stretchr/testify v1.2.2
Expand Down

0 comments on commit 67d3450

Please sign in to comment.