// Writer implements content.Ingester. desc.MediaType must be set for manifest blobs.
966450
func (i *pushingIngester) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) {
	var wOpts content.WriterOpts
	for _, opt := range opts {
		if err := opt(&wOpts); err != nil {
			return nil, err
		}
	}
	if wOpts.Ref == "" {
		return nil, errors.Wrap(errdefs.ErrInvalidArgument, "ref must not be empty")
	}
	// pusher requires desc.MediaType to determine the PUT URL, especially for manifest blobs.
	contentWriter, err := i.p.Push(ctx, wOpts.Desc)
	if err != nil {
		return nil, err
	}
	return &writer{
		Writer:           contentWriter,
		contentWriterRef: wOpts.Ref,
	}, nil
}
761178
func (w *writer) Write(b []byte) (int, error) {
	switch w.pri {
	case sInfo:
		return len(b), w.el.Info(1, string(b))
	case sWarning:
		return len(b), w.el.Warning(3, string(b))
	case sError:
		return len(b), w.el.Error(2, string(b))
	}
	return 0, fmt.Errorf("unrecognized severity: %v", w.pri)
}
1142016
func (g *Generator) Write(b []byte) (int, error) {
	return g.body.Write(b)
}
470304
func (d *driver) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error) {
	var (
		segments     []swift.Object
		segmentsPath string
		err          error
	)

	if !append {
		segmentsPath, err = d.swiftSegmentPath(path)
		if err != nil {
			return nil, err
		}
	} else {
		info, headers, err := d.Conn.Object(d.Container, d.swiftPath(path))
		if err == swift.ObjectNotFound {
			return nil, storagedriver.PathNotFoundError{Path: path}
		} else if err != nil {
			return nil, err
		}
		manifest, ok := headers["X-Object-Manifest"]
		if !ok {
			segmentsPath, err = d.swiftSegmentPath(path)
			if err != nil {
				return nil, err
			}
			if err := d.Conn.ObjectMove(d.Container, d.swiftPath(path), d.Container, getSegmentPath(segmentsPath, len(segments))); err != nil {
				return nil, err
			}
			segments = []swift.Object{info}
		} else {
			_, segmentsPath = parseManifest(manifest)
			if segments, err = d.getAllSegments(segmentsPath); err != nil {
				return nil, err
			}
		}
	}

	return d.newWriter(path, segmentsPath, segments), nil
}
34823
func (d *driver) Writer(ctx context.Context, path string, append bool) (storagedriver.FileWriter, error) {
	blobRef := d.client.GetContainerReference(d.container).GetBlobReference(path)
	blobExists, err := blobRef.Exists()
	if err != nil {
		return nil, err
	}
	var size int64
	if blobExists {
		if append {
			err = blobRef.GetProperties(nil)
			if err != nil {
				return nil, err
			}
			blobProperties := blobRef.Properties
			size = blobProperties.ContentLength
		} else {
			err = blobRef.Delete(nil)
			if err != nil {
				return nil, err
			}
		}
	} else {
		if append {
			return nil, storagedriver.PathNotFoundError{Path: path}
		}
		err = blobRef.PutAppendBlob(nil)
		if err != nil {
			return nil, err
		}
	}

	return d.newWriter(path, size), nil
}
699403
func (w *writer) write(p []byte) (int, error) {
	var err error

	if len(p) > MaxBlockSize {
		return 0, errors.New(fmt.Sprintf("block too large %d > %d", len(p), MaxBlockSize))
	}

	w.dst = w.dst[:cap(w.dst)] // Encode does dumb resize w/o context. reslice avoids alloc.
	w.dst, err = snappy.Encode(w.dst, p)
	if err != nil {
		return 0, err
	}
	block := w.dst
	n := len(p)
	compressed := true

	// check for data which is better left uncompressed.  this is determined if
	// the encoded content is longer than the source.
	if len(w.dst) >= len(p) {
		compressed = false
		block = p[:n]
	}

	if !w.sentStreamID {
		_, err := w.writer.Write(streamID)
		if err != nil {
			return 0, err
		}
		w.sentStreamID = true
	}

	// set the block type
	if compressed {
		writeHeader(w.hdr, blockCompressed, block, p[:n])
	} else {
		writeHeader(w.hdr, blockUncompressed, block, p[:n])
	}

	_, err = w.writer.Write(w.hdr)
	if err != nil {
		return 0, err
	}

	_, err = w.writer.Write(block)
	if err != nil {
		return 0, err
	}

	return n, nil
}
350746
func (w *Writer) Write(i interface{}) {
	var s string
	switch i.(type) {
	case string:
		s = i.(string)
	case []byte:
		for _, b := range i.([]byte) {
			s += fmt.Sprintf("%.8b", b)
		}
	case bool:
		if i.(bool) {
			s = "1"
		} else {
			s = "0"
		}
	case uint8:
		s = fmt.Sprintf("%.8b", i)
	case uint16:
		s = fmt.Sprintf("%.16b", i)
	case uint32:
		s = fmt.Sprintf("%.32b", i)
	case uint64:
		s = fmt.Sprintf("%.64b", i)
	default:
		return
	}

	for _, c := range s {
		w.remainingBits = w.remainingBits + string(c)
		if len(w.remainingBits) == 8 {
			var nb byte
			var power float64
			for idx := len(w.remainingBits) - 1; idx >= 0; idx-- {
				if w.remainingBits[idx] == '1' {
					nb = nb + uint8(math.Pow(2, power))
				}
				power++
			}
			w.b = append(w.b, nb)
			w.remainingBits = ""
		}
	}
}
880342
func makeWriter(typ reflect.Type, ts tags) (writer, error) {
	kind := typ.Kind()
	switch {
	case typ == rawValueType:
		return writeRawValue, nil
	case typ.Implements(encoderInterface):
		return writeEncoder, nil
	case kind != reflect.Ptr && reflect.PtrTo(typ).Implements(encoderInterface):
		return writeEncoderNoPtr, nil
	case kind == reflect.Interface:
		return writeInterface, nil
	case typ.AssignableTo(reflect.PtrTo(bigInt)):
		return writeBigIntPtr, nil
	case typ.AssignableTo(bigInt):
		return writeBigIntNoPtr, nil
	case isUint(kind):
		return writeUint, nil
	case kind == reflect.Bool:
		return writeBool, nil
	case kind == reflect.String:
		return writeString, nil
	case kind == reflect.Slice && isByte(typ.Elem()):
		return writeBytes, nil
	case kind == reflect.Array && isByte(typ.Elem()):
		return writeByteArray, nil
	case kind == reflect.Slice || kind == reflect.Array:
		return makeSliceWriter(typ, ts)
	case kind == reflect.Struct:
		return makeStructWriter(typ)
	case kind == reflect.Ptr:
		return makePtrWriter(typ)
	default:
		return nil, fmt.Errorf("rlp: type %v is not RLP-serializable", typ)
	}
}
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
}
521865
func (fs *Filespace) Writer(subPath string) (filesystem.Writer, error) {
	return os.OpenFile(fs.path+subPath, os.O_WRONLY|os.O_CREATE, filesystem.DefaultUnixFileMode)
}
303533
func (w yamlFrameWriter) Write(data []byte) (n int, err error) {
	if _, err := w.w.Write([]byte("---\n")); err != nil {
		return 0, err
	}
	return w.w.Write(data)
}
922183
func (l *Logger) Writer(level LogLevel) io.Writer {
	return &writer{l: l, level: level}
}
1000246
func (w *minifyResponseWriter) Write(b []byte) (int, error) {
	if w.writer == nil {
		// first write
		if mediatype := w.ResponseWriter.Header().Get("Content-Type"); mediatype != "" {
			w.mediatype = mediatype
		}
		w.writer = w.m.Writer(w.mediatype, w.ResponseWriter)
	}
	return w.writer.Write(b)
}
190740
func (g Generator) Write(wr io.Writer) error {
	var buf bytes.Buffer
	if err := g.mockTmpl.Execute(&buf, g); err != nil {
		return err
	}
	err := cleanimports.Clean(wr, buf.Bytes())
	if err != nil {
		err = GenerationError{
			Err:  err,
			Code: buf.Bytes(),
		}
	}
	return err
}
1110409
func StorageWriter(storage StorageAPI, volume, path string) io.Writer {
	return &storageWriter{storage, volume, path}
}
165678
func (s *store) writer(ctx context.Context, ref string, total int64, expected digest.Digest) (content.Writer, error) {
	// TODO(stevvooe): Need to actually store expected here. We have
	// code in the service that shouldn't be dealing with this.
	if expected != "" {
		p := s.blobPath(expected)
		if _, err := os.Stat(p); err == nil {
			return nil, errors.Wrapf(errdefs.ErrAlreadyExists, "content %v", expected)
		}
	}

	path, refp, data := s.ingestPaths(ref)

	var (
		digester  = digest.Canonical.Digester()
		offset    int64
		startedAt time.Time
		updatedAt time.Time
	)

	foundValidIngest := false
	// ensure that the ingest path has been created.
	if err := os.Mkdir(path, 0755); err != nil {
		if !os.IsExist(err) {
			return nil, err
		}
		status, err := s.resumeStatus(ref, total, digester)
		if err == nil {
			foundValidIngest = true
			updatedAt = status.UpdatedAt
			startedAt = status.StartedAt
			total = status.Total
			offset = status.Offset
		} else {
			logrus.Infof("failed to resume the status from path %s: %s. will recreate them", path, err.Error())
		}
	}

	if !foundValidIngest {
		startedAt = time.Now()
		updatedAt = startedAt

		// the ingest is new, we need to setup the target location.
		// write the ref to a file for later use
		if err := ioutil.WriteFile(refp, []byte(ref), 0666); err != nil {
			return nil, err
		}

		if err := writeTimestampFile(filepath.Join(path, "startedat"), startedAt); err != nil {
			return nil, err
		}

		if err := writeTimestampFile(filepath.Join(path, "updatedat"), startedAt); err != nil {
			return nil, err
		}

		if total > 0 {
			if err := ioutil.WriteFile(filepath.Join(path, "total"), []byte(fmt.Sprint(total)), 0666); err != nil {
				return nil, err
			}
		}
	}

	fp, err := os.OpenFile(data, os.O_WRONLY|os.O_CREATE, 0666)
	if err != nil {
		return nil, errors.Wrap(err, "failed to open data file")
	}

	if _, err := fp.Seek(offset, io.SeekStart); err != nil {
		return nil, errors.Wrap(err, "could not seek to current write offset")
	}

	return &writer{
		s:         s,
		fp:        fp,
		ref:       ref,
		path:      path,
		offset:    offset,
		total:     total,
		digester:  digester,
		startedAt: startedAt,
		updatedAt: updatedAt,
	}, nil
}
1222710
func (c *Container) Write(bs []byte) (size int, err error) {
	for _, w := range c.ws {
		if size, err = w.Write(bs); err != nil {
			return
		}
	}

	return
}