reader_appengine.go 867 B

12345678910111213141516171819202122232425262728
  1. // +build appengine
  2. package maxminddb
  3. import "io/ioutil"
  4. // Open takes a string path to a MaxMind DB file and returns a Reader
  5. // structure or an error. The database file is opened using a memory map,
  6. // except on Google App Engine where mmap is not supported; there the database
  7. // is loaded into memory. Use the Close method on the Reader object to return
  8. // the resources to the system.
  9. func Open(file string) (*Reader, error) {
  10. bytes, err := ioutil.ReadFile(file)
  11. if err != nil {
  12. return nil, err
  13. }
  14. return FromBytes(bytes)
  15. }
  16. // Close unmaps the database file from virtual memory and returns the
  17. // resources to the system. If called on a Reader opened using FromBytes
  18. // or Open on Google App Engine, this method sets the underlying buffer
  19. // to nil, returning the resources to the system.
  20. func (r *Reader) Close() error {
  21. r.buffer = nil
  22. return nil
  23. }