// Write replaces the data associated with the file named by path.
8805
func (c *Context) Write(path string, data []byte) error {
	if ae != nil {
		return ae.Write(c.ae, path, data)
	}
	return c.write(path, data)
}
461170
func (f *File) Write(filename string) error {
	file, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer file.Close()

	_, err = file.WriteString(f.String())
	return err
}
616171
func (z *Zip) Write(f File) error {
	if z.zw == nil {
		return fmt.Errorf("zip archive was not created for writing first")
	}
	if f.FileInfo == nil {
		return fmt.Errorf("no file info")
	}
	if f.FileInfo.Name() == "" {
		return fmt.Errorf("missing file name")
	}

	header, err := zip.FileInfoHeader(f)
	if err != nil {
		return fmt.Errorf("%s: getting header: %v", f.Name(), err)
	}

	if f.IsDir() {
		header.Name += "/" // required - strangely no mention of this in zip spec? but is in godoc...
		header.Method = zip.Store
	} else {
		ext := strings.ToLower(path.Ext(header.Name))
		if _, ok := compressedFormats[ext]; ok && z.SelectiveCompression {
			header.Method = zip.Store
		} else {
			header.Method = zip.Deflate
		}
	}

	writer, err := z.zw.CreateHeader(header)
	if err != nil {
		return fmt.Errorf("%s: making header: %v", f.Name(), err)
	}

	return z.writeFile(f, writer)
}
155913
func (f *File) Write(b []byte) (int, error) {
	if !f.writing {
		f.writing = true

		go func() {
			_, err := f.c.Files.Upload(&dropbox.UploadInput{
				Mode:   dropbox.WriteModeOverwrite,
				Path:   f.Name,
				Mute:   true,
				Reader: f.pipeR,
			})

			f.pipeR.CloseWithError(err)
		}()
	}

	return f.pipeW.Write(b)
}
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
}
1142867
func (l *MuxWriter) Write(b []byte) (int, error) {
	l.Lock()
	defer l.Unlock()
	return l.fd.Write(b)
}
934276
func (gc *gitConfig) Write(path string) error {
	f, err := os.Create(path)
	if err != nil {
		return err
	}
	defer f.Close()
	if err = gitConfigTempl.Execute(f, gc); err != nil {
		return err
	}
	return f.Close() // failure to close the file is an overall failure
}
50647
func (f *UnstageFile) Write(ctx context.Context, req *fuse.WriteRequest,
	resp *fuse.WriteResponse) (err error) {
	defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }()
	size, err := libfs.UnstageForTesting(
		ctx, f.folder.fs.log, f.folder.fs.config,
		f.folder.getFolderBranch(), req.Data)
	if err != nil {
		return err
	}
	resp.Size = size
	return nil
}
540907
func write(path string, bc <-chan []byte, berrc <-chan error) (<-chan struct{}, <-chan error) {
	done := make(chan struct{})
	errc := make(chan error)

	go func() {
		f, err := os.Create(path)

		if err != nil {
			errc <- err
			return
		}

		defer f.Close()

		w := newBufWriter(f)

		for {
			select {
			case b, ok := <-bc:
				if !ok {
					if err := w.Flush(); err != nil {
						errc <- err
						return
					}

					done <- struct{}{}

					return
				}

				if _, err := w.Write(b); err != nil {
					errc <- err
					return
				}
			case err := <-berrc:
				errc <- err
				return
			}
		}
	}()

	return done, errc
}
1345464
func Write(kiteKey string) error {
	keyPath, err := kiteKeyPath()
	if err != nil {
		return err
	}

	err = os.MkdirAll(filepath.Dir(keyPath), 0700)
	if err != nil {
		return err
	}

	// Need to remove the previous key first because we can't write over
	// when previous file's mode is 0400.
	os.Remove(keyPath)

	return ioutil.WriteFile(keyPath, []byte(kiteKey), 0400)
}
259352
func (o Output) Write(dir string) (changed, unchanged []string, err error) {
	// First pass: populate 'changed' and 'unchanged', so we have a valid result
	// even when failing midway through writes.
	changed, unchanged = o.Compare(dir)

	// Second pass: update changed files.
	for _, name := range changed {
		path := filepath.Join(dir, filepath.FromSlash(name))
		if err = os.MkdirAll(filepath.Dir(path), 0777); err != nil {
			return
		}
		if err = ioutil.WriteFile(path, o.Data[name], 0666); err != nil {
			return
		}
	}

	return
}
309518
func (f *FileStore) Write(key string, data []byte) error {
	if err := ValidateKey(key); err != nil {
		return err
	}
	if err := ensureDirectory(f.filesystem, f.directoryPath); err != nil {
		return err
	}

	return writeFile(f.filesystem, f.getPathByKey(key), data)
}
1300142
func (c *Client) Write(path string, input []byte) error {
	return c.WriteReader(path, bytes.NewReader(input))
}
833985
func write(path string, d []byte) error {
	f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, keyPerm)
	if err != nil {
		return err
	}
	defer f.Close()
	// fInfo, err := f.Stat()
	// if err != nil {
	// 	return err
	// }
	// if fInfo.Mode() != keyPerm {
	// 	return tmerrors.NewErrPermissionsChanged(f.Name(), keyPerm, fInfo.Mode())
	// }
	_, err = f.Write(d)
	if err != nil {
		return err
	}
	err = f.Sync()
	return err
}
1307521
func (d *driver) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error) {
	d.mutex.Lock()
	defer d.mutex.Unlock()

	normalized := normalize(path)

	f, err := d.root.mkfile(normalized)
	if err != nil {
		return nil, fmt.Errorf("not a file")
	}

	if !append {
		f.truncate()
	}

	return d.newWriter(f), nil
}
777428
func (aw *Writer) Write(b []byte) (n int, err error) {
	if int64(len(b)) > aw.nb {
		b = b[0:aw.nb]
		err = ErrWriteTooLong
	}
	n, werr := aw.w.Write(b)
	aw.nb -= int64(n)
	if werr != nil {
		return n, werr
	}

	if len(b)%2 == 1 { // data size must be aligned to an even byte
		n2, _ := aw.w.Write([]byte{'\n'})
		return n+n2, err
	}

	return
}
1039987
func Write(out io.Writer, node ast.Node, options Options) (err error) {
	defer errRecover(&err)

	if options.Formatter == nil {
		options.Formatter = &ES5Formatter{}
	}

	var (
		tmpOut     = &bytes.Buffer{}
		importsBuf = &bytes.Buffer{}
		s          = &state{
			wr:          tmpOut,
			options:     options,
			funcsCalled: map[string]string{},
			funcsInFile: map[string]bool{},
		}
	)

	s.scope.push()
	s.walk(node)

	if len(s.funcsCalled) > 0 {
		for _, f := range difference(s.funcsCalled, s.funcsInFile) {
			importsBuf.WriteString(s.funcsCalled[f])
			importsBuf.WriteRune('\n')
		}
		importsBuf.WriteRune('\n')
	}

	out.Write(importsBuf.Bytes())
	out.Write(tmpOut.Bytes())

	return nil
}