// writeAttachments loops over the attachments, guesses their content-type and
// writes the data as a line-broken base64 string (using the splitter mutator).
349724
func (m *MailYak) writeAttachments(mixed partCreator, splitter writeWrapper) error {
	h := make([]byte, sniffLen)

	for _, item := range m.attachments {
		hLen, err := item.content.Read(h)
		if err != nil && err != io.EOF {
			return err
		}

		if item.mimeType == "" {
			item.mimeType = http.DetectContentType(h[:hLen])
		}

		ctype := fmt.Sprintf("%s;\n\tfilename=%q", item.mimeType, item.filename)

		part, err := mixed.CreatePart(getMIMEHeader(item, ctype))
		if err != nil {
			return err
		}

		encoder := base64.NewEncoder(base64.StdEncoding, splitter.new(part))
		if _, err := encoder.Write(h[:hLen]); err != nil {
			return err
		}

		// More to write?
		if hLen == sniffLen {
			if _, err := io.Copy(encoder, item.content); err != nil {
				return err
			}
		}

		if err := encoder.Close(); err != nil {
			return err
		}
	}

	return nil
}
1160091
func (db *Database) SaveAttachment(docId string,
	docRev string, attName string,
	attType string, attContent io.Reader) (string, error) {
	url, err := buildUrl(db.dbName, docId, attName)
	if err != nil {
		return "", err
	}
	var headers = make(map[string]string)
	headers["Accept"] = "application/json"
	headers["Content-Type"] = attType
	headers["If-Match"] = docRev
	headers["Expect"] = "100-continue"

	resp, err := db.connection.request("PUT", url, attContent, headers, db.auth)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()
	return getRevInfo(resp)
}
1085493
func (sb *storageBackend) StorageAttachments(storage names.StorageTag) ([]StorageAttachment, error) {
	query := bson.D{{"storageid", storage.Id()}}
	attachments, err := sb.storageAttachments(query)
	if err != nil {
		return nil, errors.Annotatef(err, "cannot get storage attachments for storage %s", storage.Id())
	}
	return attachments, nil
}
303480
func (s *DocumentDescription) SetAttachmentsInformation(v []*AttachmentInformation) *DocumentDescription {
	s.AttachmentsInformation = v
	return s
}
1030966
func (s *DescribeChannelOutput) SetInputAttachments(v []*InputAttachment) *DescribeChannelOutput {
	s.InputAttachments = v
	return s
}
550679
func (st *State) VolumeAttachments(ids []params.MachineStorageId) ([]params.VolumeAttachmentResult, error) {
	args := params.MachineStorageIds{ids}
	var results params.VolumeAttachmentResults
	err := st.facade.FacadeCall("VolumeAttachments", args, &results)
	if err != nil {
		return nil, err
	}
	if len(results.Results) != len(ids) {
		return nil, errors.Errorf("expected %d result(s), got %d", len(ids), len(results.Results))
	}
	return results.Results, nil
}
499917
func (s *DescribeAttachmentOutput) SetAttachment(v *Attachment) *DescribeAttachmentOutput {
	s.Attachment = v
	return s
}
587104
func (e *Email) Attach(Filename string) error {
	b, err := ioutil.ReadFile(Filename)
	if err != nil {
		return err
	}

	_, fname := filepath.Split(Filename)
	e.Attachments[fname] = b
	return nil
}
350242
func (s *StorageAPI) UnitStorageAttachments(args params.Entities) (params.StorageAttachmentIdsResults, error) {
	canAccess, err := s.accessUnit()
	if err != nil {
		return params.StorageAttachmentIdsResults{}, err
	}
	result := params.StorageAttachmentIdsResults{
		Results: make([]params.StorageAttachmentIdsResult, len(args.Entities)),
	}
	for i, entity := range args.Entities {
		storageAttachmentIds, err := s.getOneUnitStorageAttachmentIds(canAccess, entity.Tag)
		if err == nil {
			result.Results[i].Result = params.StorageAttachmentIds{
				storageAttachmentIds,
			}
		}
		result.Results[i].Error = common.ServerError(err)
	}
	return result, nil
}
615923
func (s *BatchListIndexResponse) SetIndexAttachments(v []*IndexAttachment) *BatchListIndexResponse {
	s.IndexAttachments = v
	return s
}
355994
func (r Notification_Occurrence_Event) GetAttachments() (resp []datatypes.Notification_Occurrence_Event_Attachment, err error) {
	err = r.Session.DoRequest("SoftLayer_Notification_Occurrence_Event", "getAttachments", nil, &r.Options, &resp)
	return
}
1096907
func writeSlices(out io.Writer, slices ...[]byte) (err error) {
	for _, s := range slices {
		_, err = out.Write(s)
		if err != nil {
			return err
		}
	}
	return
}
409152
func (m *Message) NewAttachment() *Attachment {
	a := &Attachment{}
	m.AddAttachment(a)

	return a
}
712320
func (c *ChatUpdateCall) SetAttachments(attachments objects.AttachmentList) *ChatUpdateCall {
	c.attachments = attachments
	return c
}
23664
func (s *UpdateChannelInput) SetInputAttachments(v []*InputAttachment) *UpdateChannelInput {
	s.InputAttachments = v
	return s
}
1006565
func (c *ChatPostMessageCall) Attachment(attachment *objects.Attachment) *ChatPostMessageCall {
	c.attachments.Append(attachment)
	return c
}
1374491
func (s *GatewayAttachment) SetAttachmentType(v string) *GatewayAttachment {
	s.AttachmentType = &v
	return s
}