Skip to content

Commit

Permalink
Add NewFile for instantiating File from *os.File (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedws authored Nov 26, 2024
1 parent b7e3f0e commit e222fd1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,16 @@ type Options struct {

// New instantiates a file instance with options given a file name.
func New(name string, opts *Options) (*File, error) {

f, err := os.Open(name)
if err != nil {
return nil, err
}

return NewFile(f, opts)
}

// NewFile instantiates a file instance with options given a file handle.
func NewFile(f *os.File, opts *Options) (*File, error) {
// Memory map the file instead of using read/write.
data, err := mmap.Map(f, mmap.RDONLY, 0)
if err != nil {
Expand Down

0 comments on commit e222fd1

Please sign in to comment.