Exemplo n.º 1
0
func Mkfile(
	c rpc.Client, l rpc.Logger, ret interface{}, key string, hasKey bool, fsize int64, extra *PutExtra) (err error) {

	url := UP_HOST + "/mkfile/" + strconv.FormatInt(fsize, 10)

	if extra.MimeType != "" {
		url += "/mimeType/" + encode(extra.MimeType)
	}
	if hasKey {
		url += "/key/" + encode(key)
	}
	for k, v := range extra.Params {
		url += fmt.Sprintf("/%s/%s", k, encode(v))
	}

	buf := make([]byte, 0, 176*len(extra.Progresses))
	for _, prog := range extra.Progresses {
		buf = append(buf, prog.Ctx...)
		buf = append(buf, ',')
	}
	if len(buf) > 0 {
		buf = buf[:len(buf)-1]
	}

	return c.CallWith(l, ret, url, "application/octet-stream", bytes.NewReader(buf), len(buf))
}
Exemplo n.º 2
0
func putWrite(c rpc.Client, l rpc.Logger, ret interface{}, uptoken, key string, hasKey bool, data io.Reader, size int64, extra *PutExtra) error {

	var b bytes.Buffer
	writer := multipart.NewWriter(&b)

	err := writeMultipart(writer, uptoken, key, hasKey, extra)
	if err != nil {
		return err
	}

	lastLine := fmt.Sprintf("\r\n--%s--\r\n", writer.Boundary())
	r := bytes.NewReader([]byte(lastLine))

	bodyLen := int64(b.Len()) + size + int64(len(lastLine))
	mr := io.MultiReader(&b, data, r)

	contentType := writer.FormDataContentType()

	return c.CallWith64(l, ret, UP_HOST, contentType, mr, bodyLen)
}
Exemplo n.º 3
0
func Blockput(
	c rpc.Client, l rpc.Logger, ret *BlkputRet, body io.Reader, size int) error {

	url := ret.Host + "/bput/" + ret.Ctx + "/" + strconv.FormatUint(uint64(ret.Offset), 10)
	return c.CallWith(l, ret, url, "application/octet-stream", body, size)
}
Exemplo n.º 4
0
func Mkblock(
	c rpc.Client, l rpc.Logger, ret *BlkputRet, blockSize int, body io.Reader, size int) error {

	return c.CallWith(l, ret, UP_HOST+"/mkblk/"+strconv.Itoa(blockSize), "application/octet-stream", body, size)
}