git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/mmdb/reader_memory.go (about)

     1  //go:build appengine || plan9 || js || wasip1
     2  // +build appengine plan9 js wasip1
     3  
     4  package mmdb
     5  
     6  import "io/ioutil"
     7  
     8  // Open takes a string path to a MaxMind DB file and returns a Reader
     9  // structure or an error. The database file is opened using a memory map
    10  // on supported platforms. On platforms without memory map support, such
    11  // as WebAssembly or Google App Engine, the database is loaded into memory.
    12  // Use the Close method on the Reader object to return the resources to the system.
    13  func Open(file string) (*Reader, error) {
    14  	bytes, err := ioutil.ReadFile(file)
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  
    19  	return FromBytes(bytes)
    20  }
    21  
    22  // Close returns the resources used by the database to the system.
    23  func (r *Reader) Close() error {
    24  	r.buffer = nil
    25  	return nil
    26  }