// writeResolvConf will generate <stage1>/etc/rkt-resolv.conf if needed
178556
func writeResolvConf(cfg *RunConfig, rootfs string) {
	if cfg.DNSConfMode.Resolv != "stage0" {
		return
	}

	if err := os.Mkdir(filepath.Join(rootfs, "etc"), common.DefaultRegularDirPerm); err != nil {
		if !os.IsExist(err) {
			log.Fatalf("error creating dir %q: %v\n", "/etc", err)
		}
	}
	resolvPath := filepath.Join(rootfs, "etc/rkt-resolv.conf")
	f, err := os.Create(resolvPath)
	if err != nil {
		log.Fatalf("error writing etc/rkt-resolv.conf: %v\n", err)
	}
	defer f.Close()

	_, err = f.WriteString(common.MakeResolvConf(cfg.DNSConfig, "Generated by rkt run"))
	if err != nil {
		log.Fatalf("error writing etc/rkt-resolv.conf: %v\n", err)
	}
}
990526
func (w *gzipResponseWriter) Writer() io.Writer {
	if w.internalWriter == nil {
		w.internalWriter = w.newWriter()
	}
	return w.internalWriter
}
1355731
func WithCsvWriter(w *encoding.Writer, c io.Closer) WriterBuilder {
	return func(header []string) Writer {
		result := &writer{
			header:  header,
			builder: NewRecordBuilder(header),
			encoder: w,
			closer:  c,
		}
		result.err = result.encoder.Write(header)
		return result
	}
}
520404
func NewWriterFromConfigAsFile(configFile string) (err error) {
	singltonLock.Lock()
	defer singltonLock.Unlock()
	if nil != blog {
		return ErrAlreadyInit
	}

	// read config from file
	config, err := readConfig(configFile)
	if nil != err {
		return
	}

	if err = config.valid(); nil != err {
		return
	}

	multiWriter := new(MultiWriter)
	multiWriter.lock = new(sync.RWMutex)

	multiWriter.level = DEBUG
	if level := LevelFromString(config.MinLevel); level.valid() {
		multiWriter.level = level
	}

	multiWriter.closed = false
	multiWriter.writers = make(map[LevelType]Writer)

	for _, filter := range config.Filters {
		var rotate = false
		var timeRotate = false
		var isSocket = false
		var isConsole = false

		// get file path
		var filePath string
		if (file{}) != filter.File {
			// file do not need logrotate
			filePath = filter.File.Path
			rotate = false
		} else if (rotateFile{}) != filter.RotateFile {
			// file need logrotate
			filePath = filter.RotateFile.Path
			rotate = true
			timeRotate = TypeTimeBaseRotate == filter.RotateFile.Type
		} else if (socket{}) != filter.Socket {
			isSocket = true
		} else {
			// use console writer as default
			isConsole = true
		}

		levels := strings.Split(filter.Levels, ",")
		for _, levelStr := range levels {
			var level LevelType
			if level = LevelFromString(levelStr); !level.valid() {
				return ErrInvalidLevel
			}

			if isConsole {
				// console writer
				writer, err := newConsoleWriter(filter.Console.Redirect)
				if nil != err {
					return err
				}

				multiWriter.writers[level] = writer
				continue
			}

			if isSocket {
				// socket writer
				writer, err := newSocketWriter(filter.Socket.Network, filter.Socket.Address)
				if nil != err {
					return err
				}

				multiWriter.writers[level] = writer
				continue
			}

			// init a base file writer
			writer, err := newBaseFileWriter(filePath, timeRotate)
			if nil != err {
				return err
			}

			if rotate {
				// set logrotate strategy
				if TypeTimeBaseRotate == filter.RotateFile.Type {
					writer.SetTimeRotated(true)
					writer.SetRetentions(filter.RotateFile.Retentions)
				} else if TypeSizeBaseRotate == filter.RotateFile.Type {
					writer.SetRotateSize(filter.RotateFile.RotateSize)
					writer.SetRotateLines(filter.RotateFile.RotateLines)
					writer.SetRetentions(filter.RotateFile.Retentions)
				} else {
					return ErrInvalidRotateType
				}
			}

			// set color
			multiWriter.SetColored(filter.Colored)
			multiWriter.writers[level] = writer
		}
	}

	blog = multiWriter
	return
}
1180433
func (def *Synthdef) WriteJSON(w io.Writer) error {
	enc := json.NewEncoder(w)
	return enc.Encode(def)
}
913017
func (c *ClassifierSerializer) WriteInstancesForKey(key string, g FixedDataGrid, includeData bool) error {
	fmt.Sprintf("%v", c)
	return SerializeInstancesToTarWriter(g, c.tarWriter, key, includeData)
}
17008
func (md *RootMetadataV2) SignWriterMetadataInternally(
	ctx context.Context, codec kbfscodec.Codec,
	signer kbfscrypto.Signer) error {
	buf, err := codec.Encode(md.WriterMetadataV2)
	if err != nil {
		return err
	}

	sigInfo, err := signer.Sign(ctx, buf)
	if err != nil {
		return err
	}
	md.WriterMetadataSigInfo = sigInfo
	return nil
}
992484
func (vi *VersionInfo) WriteSyso(filename string, arch string) error {

	// Channel for generating IDs
	newID := make(chan uint16)
	go func() {
		for i := uint16(1); ; i++ {
			newID <- i
		}
	}()

	// Create a new RSRC section
	coff := coff.NewRSRC()

	// Set the architechture
	err := coff.Arch(arch)
	if err != nil {
		return err
	}

	// ID 16 is for Version Information
	coff.AddResource(16, 1, SizedReader{bytes.NewBuffer(vi.Buffer.Bytes())})

	// If manifest is enabled
	if vi.ManifestPath != "" {

		manifest, err := binutil.SizedOpen(vi.ManifestPath)
		if err != nil {
			return err
		}
		defer manifest.Close()

		id := <-newID
		coff.AddResource(rtManifest, id, manifest)
	}

	// If icon is enabled
	if vi.IconPath != "" {
		if err := addIcon(coff, vi.IconPath, newID); err != nil {
			return err
		}
	}

	coff.Freeze()

	// Write to file
	return writeCoff(coff, filename)
}
599888
func (ini *INI) write(kv Kvmap, buf *bufio.Writer) {
    for k, v := range kv {
        buf.WriteString(k)
        buf.WriteString(ini.kvSep)
        buf.WriteString(v)
        buf.WriteString(ini.lineSep)
    }
}
1183597
func (c *Call) WriteResponseHeader(k, v string) error {
	if c == nil {
		return yarpcerrors.InvalidArgumentErrorf(
			"failed to write response header: " +
				"Call was nil, make sure CallFromContext was called with a request context")
	}
	if c.ic.disableResponseHeaders {
		return yarpcerrors.InvalidArgumentErrorf("call does not support setting response headers")
	}
	c.ic.resHeaders = append(c.ic.resHeaders, keyValuePair{k: k, v: v})
	return nil
}
291440
func WriteJSON(writer io.Writer, v interface{}, options JSON, enableOptimization ...bool) (int, error) {
	var (
		result   []byte
		err      error
		optimize = len(enableOptimization) > 0 && enableOptimization[0]
	)

	if indent := options.Indent; indent != "" {
		marshalIndent := json.MarshalIndent
		if optimize {
			marshalIndent = jsoniter.ConfigCompatibleWithStandardLibrary.MarshalIndent
		}

		result, err = marshalIndent(v, "", indent)
		result = append(result, newLineB...)
	} else {
		marshal := json.Marshal
		if optimize {
			marshal = jsoniter.ConfigCompatibleWithStandardLibrary.Marshal
		}

		result, err = marshal(v)
	}

	if err != nil {
		return 0, err
	}

	if options.UnescapeHTML {
		result = bytes.Replace(result, ltHex, lt, -1)
		result = bytes.Replace(result, gtHex, gt, -1)
		result = bytes.Replace(result, andHex, and, -1)
	}

	if prefix := options.Prefix; prefix != "" {
		result = append([]byte(prefix), result...)
	}

	return writer.Write(result)
}
1130382
func WriteConfig(config *api.Config, filename string) error {
	if config == nil {
		glog.Errorf("could not write to '%s': config can't be nil", filename)
	}

	// encode config to YAML
	data, err := runtime.Encode(latest.Codec, config)
	if err != nil {
		return errors.Errorf("could not write to '%s': failed to encode config: %v", filename, err)
	}

	// create parent dir if doesn't exist
	dir := filepath.Dir(filename)
	if _, err := os.Stat(dir); os.IsNotExist(err) {
		if err = os.MkdirAll(dir, 0755); err != nil {
			return errors.Wrapf(err, "Error creating directory: %s", dir)
		}
	}

	// write with restricted permissions
	if err := ioutil.WriteFile(filename, data, 0600); err != nil {
		return errors.Wrapf(err, "Error writing file %s", filename)
	}
	if err := MaybeChownDirRecursiveToMinikubeUser(dir); err != nil {
		return errors.Wrapf(err, "Error recursively changing ownership for dir: %s", dir)
	}

	return nil
}
512295
func WithWriteConcern(wc int) ClientOptionFunc {
	return func(c *Client) error {
		if wc > 0 {
			c.safety.W = wc
		}
		return nil
	}
}
198685
func (s *ReplicaSettingsDescription) SetReplicaProvisionedWriteCapacityAutoScalingSettings(v *AutoScalingSettingsDescription) *ReplicaSettingsDescription {
	s.ReplicaProvisionedWriteCapacityAutoScalingSettings = v
	return s
}
554249
func (rw *RefWriter) WriteRefs(n ipld.Node, enc cidenc.Encoder) (int, error) {
	return rw.writeRefsRecursive(n, 0, enc)
}
1198587
func writeOnionErrorChanUpdate(w io.Writer, chanUpdate *ChannelUpdate,
	pver uint32) error {

	// First, we encode the channel update in a temporary buffer in order
	// to get the exact serialized size.
	var b bytes.Buffer
	if err := chanUpdate.Encode(&b, pver); err != nil {
		return err
	}

	// Now that we know the size, we can write the length out in the main
	// writer.
	updateLen := b.Len()
	if err := WriteElement(w, uint16(updateLen)); err != nil {
		return err
	}

	// With the length written, we'll then write out the serialized channel
	// update.
	if _, err := w.Write(b.Bytes()); err != nil {
		return err
	}

	return nil
}
54942
func NewWriter(w io.Writer) *Writer {
	enc := New()
	return &Writer{e: *enc, w: csv.NewWriter(w)}
}