// Write FileInfo.
194956
func writeFileInfo(w io.Writer, file *fileInfo, r io.Reader) error {
	err := t.ExecuteTemplate(w, "FileInfo-Before", file)
	if err != nil {
		return err
	}
	sw := &stringWriter{Writer: w}
	_, err = io.Copy(sw, r)
	if err != nil {
		return err
	}
	err = t.ExecuteTemplate(w, "FileInfo-After", file)
	return err
}
1142867
func (l *MuxWriter) Write(b []byte) (int, error) {
	l.Lock()
	defer l.Unlock()
	return l.fd.Write(b)
}
372695
func (s *Filesystem) writeLockInfo(info *LockInfo) error {
	path := s.lockInfoPath()
	info.Path = s.readPath
	info.Created = time.Now().UTC()

	log.Printf("[TRACE] statemgr.Filesystem: writing lock metadata to %s", path)
	err := ioutil.WriteFile(path, info.Marshal(), 0600)
	if err != nil {
		return fmt.Errorf("could not write lock info for %q: %s", s.readPath, err)
	}
	return nil
}
745364
func (w *tarWriter) Write(fileName, name string) error {
	fileInfo, err := os.Lstat(fileName)
	if err != nil {
		return err
	}

	link := ""
	if fileInfo.Mode()&os.ModeSymlink != 0 {
		if link, err = os.Readlink(fileName); err != nil {
			return err
		}
	}

	header, err := tar.FileInfoHeader(fileInfo, link)
	if err != nil {
		return err
	}

	header.Name = name

	if err := w.writer.WriteHeader(header); err != nil {
		return err
	}

	if header.Typeflag != tar.TypeReg && header.Typeflag != tar.TypeRegA {
		return nil
	}

	file, err := os.Open(fileName)
	if err != nil {
		return err
	}

	defer file.Close()

	_, err = io.Copy(w.writer, file)
	return err
}
1144147
func (f *StateFile) Write(code, info string, disconnected *Disconnected) error {
	st := state{
		Code:         code,
		Info:         info,
		Disconnected: disconnected,
	}

	return errors.Trace(utils.WriteYaml(f.path, st))
}
860905
func (w *Writer) Write(data []byte) (n int, err error) {
	return w.d.write(data)
}
1201740
func (f *roFile) Write(p []byte) (n int, err error) {
	return 0, ErrReadOnly
}
1029547
func (w *Writer) Write(b []byte) (int, error) {
	if len(b) == 0 {
		return 0, nil
	}

	var h = w.handler
	var e = eventPool.Get().(*events.Event)
	var s = *(*string)(unsafe.Pointer(&reflect.StringHeader{
		Data: uintptr(unsafe.Pointer(&b[0])),
		Len:  len(b),
	}))
	var t time.Time
	var src string

	if h == nil {
		h = events.DefaultHandler
	}

	w.mutex.Lock()
	flags, prefix := w.flags, w.prefix

	if strings.HasPrefix(s, prefix) {
		s = s[len(prefix):]
	}

	if format := timeFormat(flags); len(format) != 0 {
		var tz *time.Location
		var ts string

		if n := len(format); len(s) >= n {
			ts, s = s[:n], s[n:]
		} else {
			ts, s = s, ""
		}

		if (flags & LUTC) != 0 {
			tz = time.UTC
		} else {
			tz = time.Local
		}

		t, _ = time.ParseInLocation(format, ts, tz)
	}

	if (flags & (Llongfile | Lshortfile)) != 0 {
		var base string
		var file string
		var line string

		s = skip(s, ' ')
		base = s
		file, s = parse(s, ':') // parse the file name or path
		line, s = parse(s, ':') // parse the line number

		src = base[:len(file)+len(line)+1]
	}

	s = skip(s, ' ')

	if n := strings.IndexByte(s, '\n'); n >= 0 {
		s = s[:n]
	}

	if t == (time.Time{}) {
		t = time.Now()
	}

	e.Message = s
	e.Source = src
	e.Time = t

	h.HandleEvent(e)
	w.mutex.Unlock()

	e.Message = ""
	e.Source = ""
	e.Time = time.Time{}
	eventPool.Put(e)

	return len(b), nil
}
1329359
func (hook *LfsHook) fileWrite(entry *logrus.Entry) error {
	var (
		fd   *os.File
		path string
		msg  []byte
		err  error
		ok   bool
	)

	if path, ok = hook.paths[entry.Level]; !ok {
		if hook.hasDefaultPath {
			path = hook.defaultPath
		} else {
			return nil
		}
	}

	dir := filepath.Dir(path)
	os.MkdirAll(dir, os.ModePerm)

	fd, err = os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
	if err != nil {
		log.Println("failed to open logfile:", path, err)
		return err
	}
	defer fd.Close()

	// use our formatter instead of entry.String()
	msg, err = hook.formatter.Format(entry)

	if err != nil {
		log.Println("failed to generate string for entry:", err)
		return err
	}
	fd.Write(msg)
	return nil
}
569246
func (f DumFile) Write(p []byte) (n int, err error) {
	return 0, f.err
}
1335333
func (f *ResetCachesFile) Write(ctx context.Context, req *fuse.WriteRequest,
	resp *fuse.WriteResponse) (err error) {
	f.fs.log.CDebugf(ctx, "ResetCachesFile Write")
	defer func() { err = f.fs.processError(ctx, libkbfs.WriteMode, err) }()
	if len(req.Data) == 0 {
		return nil
	}
	f.fs.config.ResetCaches()
	resp.Size = len(req.Data)
	return nil
}
846735
func (l *LogFile) Write(b []byte) (n int, err error) {
	// Filter out log entries that do not match log level criteria
	if !l.logFilter.Check(b) {
		return 0, nil
	}

	l.acquire.Lock()
	defer l.acquire.Unlock()
	//Create a new file if we have no file to write to
	if l.FileInfo == nil {
		if err := l.openNew(); err != nil {
			return 0, err
		}
	}
	// Check for the last contact and rotate if necessary
	if err := l.rotate(); err != nil {
		return 0, err
	}
	l.BytesWritten += int64(len(b))
	return l.FileInfo.Write(b)
}
1069245
func (w *DataFileWriter) Write(v interface{}) error {
	w.blockCount++
	err := w.datumWriter.Write(v, w.blockEnc)
	return err
}
53807
func (f *SyncFromServerFile) Write(ctx context.Context, req *fuse.WriteRequest,
	resp *fuse.WriteResponse) (err error) {
	f.folder.fs.log.CDebugf(ctx, "SyncFromServerFile Write")
	defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }()
	if len(req.Data) == 0 {
		return nil
	}
	folderBranch := f.folder.getFolderBranch()
	if folderBranch == (data.FolderBranch{}) {
		// Nothing to do.
		resp.Size = len(req.Data)
		return nil
	}

	// Use a context with a nil CtxAppIDKey value so that
	// notifications generated from this sync won't be discarded.
	syncCtx := context.WithValue(ctx, libfs.CtxAppIDKey, nil)
	err = f.folder.fs.config.KBFSOps().SyncFromServer(
		syncCtx, folderBranch, nil)
	if err != nil {
		return err
	}
	f.folder.fs.NotificationGroupWait()
	resp.Size = len(req.Data)
	return nil
}
702433
func (t *File) Write(p []byte) (int, error) {
	if t.fh == nil {
		return 0, errors.Errorf("not initialized")
	}
	return t.fh.Write(p)
}
1204694
func (f *FileWriter) Write(b []byte) (int, error) {
	if f.closed {
		return 0, io.ErrClosedPipe
	}

	if f.blockWriter == nil {
		err := f.startNewBlock()
		if err != nil {
			return 0, err
		}
	}

	off := 0
	for off < len(b) {
		n, err := f.blockWriter.Write(b[off:])
		off += n
		if err == rpc.ErrEndOfBlock {
			err = f.startNewBlock()
		}

		if err != nil {
			return off, err
		}
	}

	return off, nil
}
30601
func (g *Generator) Write(output string) {
	if err := ioutil.WriteFile(output, g.buf.Bytes(), 0644); err != nil {
		log.Fatalln(err)
	}
}