// NewPartInlineFromBytes creates an inline part,
// using the filename's mime type, specified Content-ID
// (do not wrap with angle brackets), and with the bytes as its content
// (do not encode, this will happen automatically when needed).
334816
func NewPartInlineFromBytes(raw []byte, filename string, contentID string) *Message {
	return newPartFromBytes(raw, mime.TypeByExtension(filepath.Ext(filename)), "inline; filename=\""+filename+"\"", contentID)
}
340536
func NewLine(tags core.TagSlice) (*Line, error) {
	line := new(Line)

	// set defaults
	line.ExtrusionDirection = core.Point{X: 0.0, Y: 0.0, Z: 1.0}

	line.InitBaseEntityParser()
	line.Update(map[int]core.TypeParser{
		39:  core.NewFloatTypeParserToVar(&line.Thickness),
		10:  core.NewFloatTypeParserToVar(&line.Start.X),
		20:  core.NewFloatTypeParserToVar(&line.Start.Y),
		30:  core.NewFloatTypeParserToVar(&line.Start.Z),
		11:  core.NewFloatTypeParserToVar(&line.End.X),
		21:  core.NewFloatTypeParserToVar(&line.End.Y),
		31:  core.NewFloatTypeParserToVar(&line.End.Z),
		210: core.NewFloatTypeParserToVar(&line.ExtrusionDirection.X),
		220: core.NewFloatTypeParserToVar(&line.ExtrusionDirection.Y),
		230: core.NewFloatTypeParserToVar(&line.ExtrusionDirection.Z),
	})

	err := line.Parse(tags)
	return line, err
}
546913
func (m *Multi) PutPartCopyWithContentLength(n int, options CopyOptions, source string, contentLength int64) (*CopyObjectResult, Part, error) {
	// TODO source format a /BUCKET/PATH/TO/OBJECT
	// TODO not a good design. API could be changed to PutPartCopyWithinBucket(..., path) and PutPartCopyFromBucket(bucket, path)

	headers := make(http.Header)
	headers.Set("x-oss-copy-source", source)

	options.addHeaders(headers)
	params := make(url.Values)
	params.Set("uploadId", m.UploadId)
	params.Set("partNumber", strconv.FormatInt(int64(n), 10))

	if contentLength < 0 {
		sourceBucket := m.Bucket.Client.Bucket(strings.TrimRight(strings.Split(source, "/")[1], "/"))
		//log.Println("source: ", source)
		//log.Println("sourceBucket: ", sourceBucket.Name)
		//log.Println("HEAD: ", strings.strings.SplitAfterN(source, "/", 3)[2])
		// TODO SplitAfterN can be use in bucket name
		sourceMeta, err := sourceBucket.Head(strings.SplitAfterN(source, "/", 3)[2], nil)
		if err != nil {
			return nil, Part{}, err
		}
		contentLength = sourceMeta.ContentLength
	}

	for attempt := attempts.Start(); attempt.Next(); {
		req := &request{
			method:  "PUT",
			bucket:  m.Bucket.Name,
			path:    m.Key,
			headers: headers,
			params:  params,
		}
		resp := &CopyObjectResult{}
		err := m.Bucket.Client.query(req, resp)
		if shouldRetry(err) && attempt.HasNext() {
			continue
		}
		if err != nil {
			return nil, Part{}, err
		}
		if resp.ETag == "" {
			return nil, Part{}, errors.New("part upload succeeded with no ETag")
		}
		return resp, Part{n, resp.ETag, contentLength}, nil
	}
	panic("unreachable")
}
150338
func (bi *BinaryInfo) AllPCsForFileLine(filename string, lineno int) []uint64 {
	r := make([]uint64, 0, 1)
	for _, cu := range bi.compileUnits {
		if cu.lineInfo.Lookup[filename] != nil {
			r = append(r, cu.lineInfo.AllPCsForFileLine(filename, lineno)...)
		}
	}
	return r
}
1269825
func NewPartition(namespace string, partitionID int) *Partition {
	return &Partition{
		Namespace:   namespace,
		PartitionId: partitionID,
	}
}
1291222
func NewLinesReaderSizeFromFile(filename string, bufsize int) (r *LinesReader, err error) {
	r = &LinesReader{interrupt: make(chan bool)}
	r.f, err = os.Open(filename)
	if err != nil {
		return
	}
	if strings.HasSuffix(filename, ".gz") {
		r.rz, err = gzip.NewReader(r.f)
		if err != nil {
			r.f.Close()
			return
		}
		r.r = NewReaderSize(r.rz, bufsize)
		r.isGzip = true
	} else if strings.HasSuffix(filename, ".bz2") {
		r.bz2 = bzip2.NewReader(r.f)
		r.r = NewReader(r.bz2)
	} else {
		r.r = NewReader(r.f)
	}
	r.isOpen = true
	r.needClose = true
	return
}
559826
func NewPluginRoutingFromBytes(bytes []byte) (PluginRouting, error) {
	var routing PluginRouting
	if err := yaml.Unmarshal(bytes, &routing); err != nil {
		return PluginRouting{}, err
	}
	if err := routing.Validate(); err != nil {
		return PluginRouting{}, err
	}
	return routing, nil
}
635907
func CreateFile(name string, content []byte) *File {
	mimeType := mime.TypeByExtension(filepath.Ext(name))
	if mimeType == "" {
		mimeType = "application/octet-stream"
	}

	return &File{
		Name:     name,
		MimeType: mimeType,
		Content:  content,
	}
}
551689
func ParseMIME(reader *bufio.Reader) (MIMEPart, error) {
	tr := textproto.NewReader(reader)
	header, err := tr.ReadMIMEHeader()
	if err != nil {
		return nil, err
	}
	mediatype, params, err := mime.ParseMediaType(header.Get("Content-Type"))
	if err != nil {
		return nil, err
	}
	root := &memMIMEPart{header: header, contentType: mediatype}

	if strings.HasPrefix(mediatype, "multipart/") {
		boundary := params["boundary"]
		err = parseParts(root, reader, boundary)
		if err != nil {
			return nil, err
		}
	} else {
		// Content is text or data, decode it
		content, err := decodeSection(header.Get("Content-Transfer-Encoding"), reader)
		if err != nil {
			return nil, err
		}
		root.content = content
	}

	return root, nil
}
202883
func (w *Writer) CreateInline() (*InlineWriter, error) {
	var h message.Header
	h.Set("Content-Type", "multipart/alternative")

	mw, err := w.mw.CreatePart(h)
	if err != nil {
		return nil, err
	}
	return &InlineWriter{mw}, nil
}
260374
func NewDefaultTrimaForStream(priceStream gotrade.DOHLCVStreamSubscriber) (indicator *Trima, err error) {
	ind, err := NewDefaultTrima()
	priceStream.AddTickSubscription(ind)
	return ind, err
}
841407
func ReadFirstLineOfFile(file string) string {
	return strings.TrimSpace(strings.Split(string(ReadBinaryFromFile(file)), "\n")[0])
}
916440
func NewDefaultTrimaForStreamWithSrcLen(sourceLength uint, priceStream gotrade.DOHLCVStreamSubscriber) (indicator *Trima, err error) {
	ind, err := NewDefaultTrimaWithSrcLen(sourceLength)
	priceStream.AddTickSubscription(ind)
	return ind, err
}
1244741
func NewPartAttachment(r io.Reader, filename string) (*Message, error) {
	b, err := ioutil.ReadAll(r)
	if err != nil {
		return nil, err
	}
	return NewPartAttachmentFromBytes(b, filename), nil
}
831624
func NewInlineQueryResultCachedMPEG4GIF(id, MPEG4GifID string) InlineQueryResultCachedMpeg4Gif {
	return InlineQueryResultCachedMpeg4Gif{
		Type:   "mpeg4_gif",
		ID:     id,
		MGifID: MPEG4GifID,
	}
}
498049
func NewPartSetFromData(data []byte, partSize int) *PartSet {
	// divide data into 4kb parts.
	total := (len(data) + partSize - 1) / partSize
	parts := make([]*Part, total)
	partsBytes := make([][]byte, total)
	partsBitArray := cmn.NewBitArray(total)
	for i := 0; i < total; i++ {
		part := &Part{
			Index: i,
			Bytes: data[i*partSize : cmn.MinInt(len(data), (i+1)*partSize)],
		}
		parts[i] = part
		partsBytes[i] = part.Bytes
		partsBitArray.SetIndex(i, true)
	}
	// Compute merkle proofs
	root, proofs := merkle.SimpleProofsFromByteSlices(partsBytes)
	for i := 0; i < total; i++ {
		parts[i].Proof = *proofs[i]
	}
	return &PartSet{
		total:         total,
		hash:          root,
		parts:         parts,
		partsBitArray: partsBitArray,
		count:         total,
	}
}
188531
func callPostMixFunction(udata unsafe.Pointer, stream *C.Uint8, length C.int) {
	var slice []uint8
	header := (*reflect.SliceHeader)(unsafe.Pointer(&slice))
	header.Data = uintptr(unsafe.Pointer(stream))
	header.Len = int(length)
	header.Cap = int(length)
	postMixFunc(slice)
}