// NewMemoryMappedWriter will create and return a new instance of a MemoryMappedWriter
NewMemoryMappedWriter will create and return a new instance of a MemoryMappedWriter
// NewMemoryMappedWriter will create and return a new instance of a MemoryMappedWriter
func NewMemoryMappedWriter(loc string, size int) (*MemoryMappedWriter, error) {
	if _, err := os.Stat(loc); err == nil {
		err = os.Remove(loc)
		if err != nil {
			return nil, err
		}
	}
	dir := filepath.Dir(loc)
	err := os.MkdirAll(dir, 0700)
	if err != nil {
		return nil, err
	}
	f, err := os.OpenFile(loc, os.O_CREATE|os.O_RDWR|os.O_EXCL, 0644)
	if err != nil {
		return nil, err
	}
	l, err := f.Write(make([]byte, size))
	if err != nil {
		return nil, err
	}
	if l < size {
		return nil, errors.Errorf("Could not initialize %d bytes", size)
	}
	b, err := mmap.Map(f, mmap.RDWR, 0)
	if err != nil {
		return nil, err
	}
	return &MemoryMappedWriter{
		NewByteWriterSlice(b),
		f,
		loc,
		size,
	}, nil
}
func NewMemoryMappedWriter ( loc string , size int ) ( * MemoryMappedWriter , error ) { if _ , err := os . Stat ( loc ) ; err == nil { err = os . Remove ( loc ) if err != nil { return nil , err } } dir := filepath . Dir ( loc ) err := os . MkdirAll ( dir , 0700 ) if err != nil { return nil , err } f , err := os . OpenFile ( loc , os . O_CREATE | os . O_RDWR | os . O_EXCL , 0644 ) if err != nil { return nil , err } l , err := f . Write ( make ( [ ] byte , size ) ) if err != nil { return nil , err } if l < size { return nil , errors . Errorf ( " " , size ) } b , err := mmap . Map ( f , mmap . RDWR , 0 ) if err != nil { return nil , err } return & MemoryMappedWriter { NewByteWriterSlice ( b ) , f , loc , size , } , nil }
NewMemoryMappedWriter will create and return a new instance of a MemoryMappedWriter
NewMemoryMappedWriter will create and return a new instance of a MemoryMappedWriter
// ensure destination directory exists