github.com/database64128/shadowsocks-go@v1.10.2-0.20240315062903-143a773533f1/mmap/mmap_generic.go (about) 1 //go:build !unix && !windows 2 3 package mmap 4 5 import ( 6 "os" 7 "unsafe" 8 ) 9 10 // ReadFile maps the named file into memory for reading. 11 func ReadFile[T ~[]byte | ~string](name string) (data T, err error) { 12 b, err := os.ReadFile(name) 13 if err != nil { 14 return 15 } 16 return *(*T)(unsafe.Pointer(&b)), nil 17 } 18 19 // Unmap removes the memory mapping. 20 func Unmap[T ~[]byte | ~string](b T) error { 21 return nil 22 }