...

Source file src/cmd/go/internal/mmap/mmap.go

Documentation: cmd/go/internal/mmap

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // This package is a lightly modified version of the mmap code
     6  // in github.com/google/codesearch/index.
     7  
     8  // The mmap package provides an abstraction for memory mapping files
     9  // on different platforms.
    10  package mmap
    11  
    12  import (
    13  	"os"
    14  )
    15  
    16  // Data is mmap'ed read-only data from a file.
    17  // The backing file is never closed, so Data
    18  // remains valid for the lifetime of the process.
    19  type Data struct {
    20  	f    *os.File
    21  	Data []byte
    22  }
    23  
    24  // Mmap maps the given file into memory.
    25  func Mmap(file string) (Data, error) {
    26  	f, err := os.Open(file)
    27  	if err != nil {
    28  		return Data{}, err
    29  	}
    30  	return mmapFile(f)
    31  }
    32  

View as plain text