// SaveTo saves secret data to given directory
491955
func (s SecretData) SaveTo(dir string) error {
	path := filepath.Join(dir, s.Name)
	if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil && !os.IsExist(err) {
		return err
	}
	return ioutil.WriteFile(path, s.Data, 0700)
}
44778
func (f *FlowRemoved) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, f.Cookie, f.Priority, f.Reason,
		f.Table, f.DurationSec, f.DurationNSec, f.IdleTimeout,
		f.HardTimeout, f.PacketCount, f.ByteCount, &f.Match,
	)
}
887750
func (f *freeClientPool) saveToDb() {
	now := f.clock.Now()
	storage := freeClientPoolStorage{
		LogOffset: uint64(f.logOffset(now)),
		List:      make([]*freeClientPoolEntry, len(f.addressMap)),
	}
	i := 0
	for _, e := range f.addressMap {
		if e.connected {
			f.calcLogUsage(e, now)
		}
		storage.List[i] = e
		i++
	}
	enc, err := rlp.EncodeToBytes(storage)
	if err != nil {
		log.Error("Failed to encode client list", "err", err)
	} else {
		f.db.Put([]byte("freeClientPool"), enc)
	}
}
592205
func (e *ErrorExperimenter) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, ErrTypeExperimenter, e.ExpType,
		e.Experimenter, e.Data)
}
289642
func (f *decompressor) WriteTo(w io.Writer) (int64, error) {
	total := int64(0)
	flushed := false
	for {
		if len(f.toRead) > 0 {
			n, err := w.Write(f.toRead)
			total += int64(n)
			if err != nil {
				f.err = err
				return total, err
			}
			if n != len(f.toRead) {
				return total, io.ErrShortWrite
			}
			f.toRead = f.toRead[:0]
		}
		if f.err != nil && flushed {
			if f.err == io.EOF {
				return total, nil
			}
			return total, f.err
		}
		if f.err == nil {
			f.step(f)
		}
		if len(f.toRead) == 0 && f.err != nil && !flushed {
			f.toRead = f.dict.readFlush() // Flush what's left in case of error
			flushed = true
		}
	}
}
231647
func (n *Node) saveToStorage(
	ctx context.Context,
	raftConfig *api.RaftConfig,
	hardState raftpb.HardState,
	entries []raftpb.Entry,
	snapshot raftpb.Snapshot,
) (err error) {

	if !raft.IsEmptySnap(snapshot) {
		if err := n.raftLogger.SaveSnapshot(snapshot); err != nil {
			return errors.Wrap(err, "failed to save snapshot")
		}
		if err := n.raftLogger.GC(snapshot.Metadata.Index, snapshot.Metadata.Term, raftConfig.KeepOldSnapshots); err != nil {
			log.G(ctx).WithError(err).Error("unable to clean old snapshots and WALs")
		}
		if err = n.raftStore.ApplySnapshot(snapshot); err != nil {
			return errors.Wrap(err, "failed to apply snapshot on raft node")
		}
	}

	if err := n.raftLogger.SaveEntries(hardState, entries); err != nil {
		return errors.Wrap(err, "failed to save raft log entries")
	}

	if len(entries) > 0 {
		lastIndex := entries[len(entries)-1].Index
		if lastIndex > n.writtenWALIndex {
			n.writtenWALIndex = lastIndex
		}
	}

	if err = n.raftStore.Append(entries); err != nil {
		return errors.Wrap(err, "failed to append raft log entries")
	}

	return nil
}
790834
func (tms *TrustMetricStore) saveToDB() {
	tms.Logger.Debug("Saving TrustHistory to DB", "size", tms.size())

	peers := make(map[string]MetricHistoryJSON)

	for key, tm := range tms.peerMetrics {
		// Add an entry for the peer identified by key
		peers[key] = tm.HistoryJSON()
	}

	// Write all the data back to the DB
	bytes, err := json.Marshal(peers)
	if err != nil {
		tms.Logger.Error("Failed to encode the TrustHistory", "err", err)
		return
	}
	tms.db.SetSync(trustMetricKey, bytes)
}
796873
func (g *GroupMod) WriteTo(w io.Writer) (int64, error) {
	n, err := encoding.WriteTo(w, g.Command, g.Type, pad1{}, g.Group)
	if err != nil {
		return n, err
	}

	nn, err := encoding.WriteSliceTo(w, g.Buckets)
	return n + nn, err
}
1208646
func (f *File) WriteTo(w io.Writer) (int64, error) {
	return f.WriteToIndent(w, "")
}
1354595
func (d Dockerfile) WriteTo(w io.Writer) (n int64, err error) {
	bw := bufio.NewWriter(w)
	defer bw.Flush()
	i, err := bw.WriteString(fmt.Sprintf("## RECREATED FROM IMAGE ON %s\n", time.Now().Format(time.RFC3339)))
	if err != nil {
		return n, err
	}
	n += int64(i)
	i, err = bw.WriteString(fmt.Sprintf("## %s:%s (%s)\n\n", d.Ref.Name, d.Ref.Tag, d.Ref.ID))
	if err != nil {
		return n, err
	}
	n += int64(i)
	for _, layer := range d.Layers {
		i, err = bw.WriteString(layer.DockerfileInstruction().String() + "\n")
		if err != nil {
			return n, err
		}
		n += int64(i)
	}
	return n, nil
}
1097085
func (f File) WriteTo(w io.Writer) (int64, error) {
	n, err := w.Write(f.data)
	if err == nil {
		if n != len(f.data) {
			// this shouldn't happen
			//
			//    Write must return a non-nil error if it returns n < len(p)
			//
			// but check just in case
			return int64(n), io.ErrShortWrite
		}
	}
	return int64(n), err
}
793284
func (f *File) SaveToIndent(filename, indent string) error {
	// Note: Because we are truncating with os.Create,
	// 	so it's safer to save to a temporary file location and rename afte done.
	buf, err := f.writeToBuffer(indent)
	if err != nil {
		return err
	}

	return ioutil.WriteFile(filename, buf.Bytes(), 0666)
}
240957
func (p *SSHPath) WriteTo(out io.Writer) (int64, error) {
	sftpClient, err := p.newClient()
	if err != nil {
		return 0, err
	}
	defer sftpClient.Close()

	f, err := sftpClient.Open(p.path)
	if err != nil {
		return 0, fmt.Errorf("error opening file %s over sftp: %v", p, err)
	}
	defer f.Close()

	return f.WriteTo(out)
}
293247
func (cp *ClientProfile) SaveTo(loc ProfileLocation) error {
	bytes, err := yaml.Marshal(&cp)
	if err != nil {
		return trace.Wrap(err)
	}
	if err = ioutil.WriteFile(loc.Path, bytes, 0660); err != nil {
		return trace.Wrap(err)
	}
	if loc.AliasPath != "" && filepath.Base(loc.AliasPath) != filepath.Base(loc.Path) {
		if err := os.Remove(loc.AliasPath); err != nil {
			log.Warningf("Failed to remove symlink alias: %v", err)
		}
		err := os.Symlink(filepath.Base(loc.Path), loc.AliasPath)
		if err != nil {
			log.Warningf("Failed to create profile alias: %v", err)
		}
	}
	// set 'current' symlink:
	if loc.Options&ProfileMakeCurrent != 0 {
		symlink := filepath.Join(filepath.Dir(loc.Path), CurrentProfileSymlink)
		if err := os.Remove(symlink); err != nil {
			log.Warningf("Failed to remove symlink: %v", err)
		}
		err = os.Symlink(filepath.Base(loc.Path), symlink)
	}
	return trace.Wrap(err)
}
341359
func CopyTo(src, dest string) error {
	fi, err := os.Open(src)
	if err != nil {
		return err
	}
	defer fi.Close()

	if runtime.GOOS == "windows" {
		// On windows, we need to remove this file first if it's in-use
		// (i.e., IPFS is running).
		if err := forceRemove(dest); err != nil {
			return fmt.Errorf("copy dest exists and can not be deleted: %s", err)
		}
	}

	trgt, err := os.Create(dest)
	if err != nil {
		return err
	}
	defer trgt.Close()

	_, err = io.Copy(trgt, fi)
	return err
}
1142691
func (w *Writer) DumpTo(out io.Writer) (written int, err error) {
	return w.Buffer.DumpTo(out)
}
927256
func (f *FlowMod) WriteTo(w io.Writer) (int64, error) {
	return encoding.WriteTo(w, f.Cookie, f.CookieMask, f.Table,
		f.Command, f.IdleTimeout, f.HardTimeout, f.Priority,
		f.Buffer, f.OutPort, f.OutGroup, f.Flags, pad2{},
		&f.Match, &f.Instructions,
	)
}