// WriteDeleteCmd writes out the binary representation of a delete request header to the given io.Writer
965881
func WriteDeleteCmd(w io.Writer, key []byte, opaque uint32) error {
	//fmt.Printf("Delete: key: %v | totalBodyLength: %v\n", string(key), len(key))
	return writeKeyCmd(w, OpcodeDelete, key, opaque)
}
742468
func (h Handler) Delete(cmd common.DeleteRequest) error {
	// read metadata
	// delete metadata
	// for 0 to metadata.numChunks
	//  delete item

	metaKey, metaData, err := getMetadata(h.rw, cmd.Key)

	if err != nil {
		if err == common.ErrKeyNotFound {
			metrics.IncCounter(MetricCmdDeleteMissesMeta)
		}
		return err
	}

	// Delete metadata first
	if err := binprot.WriteDeleteCmd(h.rw.Writer, metaKey, 0); err != nil {
		return err
	}
	if err := simpleCmdLocal(h.rw, true); err != nil {
		if err == common.ErrKeyNotFound {
			metrics.IncCounter(MetricCmdDeleteMissesMeta)
		}
		return err
	}

	// Then delete data chunks
	for i := 0; i < int(metaData.NumChunks); i++ {
		chunkKey := chunkKey(cmd.Key, i)
		if err := binprot.WriteDeleteCmd(h.rw.Writer, chunkKey, 0); err != nil {
			return err
		}
	}

	if err := h.rw.Flush(); err != nil {
		return err
	}

	miss := false
	for i := 0; i < int(metaData.NumChunks); i++ {
		if err := simpleCmdLocal(h.rw, false); err != nil {
			if err == common.ErrKeyNotFound && !miss {
				metrics.IncCounter(MetricCmdDeleteMissesChunk)
				miss = true
			}
		}
	}

	if miss {
		return common.ErrKeyNotFound
	}

	return nil
}
860905
func (w *Writer) Write(data []byte) (n int, err error) {
	return w.d.write(data)
}
687369
func (w *BatchedFileWriter) Write(p []byte) (n int, err error) {
	return w.file.Write(p)
}
1049122
func WriteHeader(w io.Writer, h Header) error {
	// TODO: wrap lines when necessary

	for i := len(h.l) - 1; i >= 0; i-- {
		f := h.l[i]

		if f.b == nil {
			f.b = []byte(formatHeaderField(f.k, f.v))
		}

		if _, err := w.Write(f.b); err != nil {
			return err
		}
	}

	_, err := w.Write([]byte{'\r', '\n'})
	return err
}
537596
func WriteGetCmd(w io.Writer, key []byte, opaque uint32) error {
	//fmt.Printf("Get: key: %v | totalBodyLength: %v\n", string(key), len(key))
	return writeKeyCmd(w, OpcodeGet, key, opaque)
}
300824
func (c *Client) Del(keys ...string) (int64, error) {
	var ret int64
	args := make([][]byte, len(keys)+1)
	args[0] = []byte("DEL")
	for i, key := range keys {
		args[1+i] = to.Bytes(key)
	}
	err := c.command(&ret, args...)
	return ret, err
}
1075772
func cmder(cmdch <-chan string, addconnch, delconnch <-chan *cmdConn) {
	cmdconns := map[*w.Conn](chan bool){}
	for {
		select {
		case c := <-addconnch:
			cmdconns[c.ws] = c.respch
		case c := <-delconnch:
			delete(cmdconns, c.ws)
		case c := <-cmdch:
			cmd := fmt.Sprintf(`{"cmd": "%s"}`, c)
			for ws, respch := range cmdconns {
				// Error ignored because we close no matter what
				_ = w.Message.Send(ws, cmd)
				respch <- true
			}
		}
	}
}
1324120
func (w *BackupStreamWriter) WriteHeader(hdr *BackupHeader) error {
	if w.bytesLeft != 0 {
		return fmt.Errorf("missing %d bytes", w.bytesLeft)
	}
	name := utf16.Encode([]rune(hdr.Name))
	wsi := win32StreamId{
		StreamId:   hdr.Id,
		Attributes: hdr.Attributes,
		Size:       uint64(hdr.Size),
		NameSize:   uint32(len(name) * 2),
	}
	if hdr.Id == BackupSparseBlock {
		// Include space for the int64 block offset
		wsi.Size += 8
	}
	if err := binary.Write(w.w, binary.LittleEndian, &wsi); err != nil {
		return err
	}
	if len(name) != 0 {
		if err := binary.Write(w.w, binary.LittleEndian, name); err != nil {
			return err
		}
	}
	if hdr.Id == BackupSparseBlock {
		if err := binary.Write(w.w, binary.LittleEndian, hdr.Offset); err != nil {
			return err
		}
	}
	w.bytesLeft = hdr.Size
	return nil
}
1159217
func (mw multiWriter) Write(p []byte) (int, error) {
	done := make(chan result, len(mw))
	for _, w := range mw {
		go send(w, p, done)
	}
	endResult := result{n: len(p)}
	for _ = range mw {
		res := <-done
		if res.err != nil && (endResult.err == nil || res.n < endResult.n) {
			endResult = res
		}
	}
	return endResult.n, endResult.err
}
1221761
func (h Handler) Delete(cmd common.DeleteRequest) error {
	_, err := h.doRequest(cmd, common.RequestDelete)
	return err
}
808328
func (d *Driver) SendCommand(cmd string) (err error) {
	_, err = d.cmdConn.Write([]byte(cmd))
	return
}
319650
func (w *statusResponseWriter) WriteHeader(statusCode int) {
	w.statusCode = statusCode
	w.ResponseWriter.WriteHeader(statusCode)
}
937252
func WriteSetCmd(w io.Writer, key []byte, flags, exptime, dataSize, opaque uint32) error {
	//fmt.Printf("Set: key: %v | flags: %v | exptime: %v | dataSize: %v | totalBodyLength: %v\n",
	//string(key), flags, exptime, dataSize, totalBodyLength)
	return writeDataCmdCommon(w, OpcodeSet, key, flags, exptime, dataSize, opaque)
}
233381
func (p *TCompactProtocol) writeByteDirect(b byte) (int, error) {
	return p.trans.Write([]byte{b})
}
50972
func (mc MongoClient) DeleteCommandById(id string) error {
	s := mc.session.Copy()
	defer s.Close()
	col := s.DB(mc.database.Name).C(db.Command)

	// Check if the command is still in use
	findParameters, err := idToBsonM(id)
	if err != nil {
		return err
	}
	query := bson.M{"commands": bson.M{"$elemMatch": findParameters}}
	count, err := s.DB(mc.database.Name).C(db.DeviceProfile).Find(query).Count()
	if err != nil {
		return errorMap(err)
	}
	if count > 0 {
		return db.ErrCommandStillInUse
	}

	// remove the command
	n, v, err := idToQueryParameters(id)
	if err != nil {
		return err
	}
	return errorMap(col.Remove(bson.D{{Name: n, Value: v}}))
}
174661
func (w *fdSyncWriter) Write(p []byte) (n int, err error) {
	w.Lock()
	n, err = w.fdWriter.Write(p)
	w.Unlock()
	return n, err
}