示例#1
0
func (v *VirStorageVol) Download(stream *VirStream, offset, length uint64, flags uint32) error {
	if C.virStorageVolDownload(v.ptr, stream.ptr, C.ulonglong(offset),
		C.ulonglong(length), C.uint(flags)) == -1 {
		return GetLastError()
	}
	return nil
}
// Download downloads the content of the volume as a stream. If "length" is
// zero, then the remaining contents of the volume after "offset" will
// be downloaded.
// This call sets up an asynchronous stream; subsequent use of stream APIs is
// necessary to transfer the actual data, determine how much data is
// successfully transferred, and detect any errors. The results will be
// unpredictable if another active stream is writing to the storage volume.
func (vol StorageVolume) Download(str Stream, offset uint64, length uint64) error {
	vol.log.Printf("setting up to download %v bytes of data from storage volume in offset %v...\n", length, offset)
	cRet := C.virStorageVolDownload(vol.virStorageVol, str.virStream, C.ulonglong(offset), C.ulonglong(length), 0)
	ret := int32(cRet)

	if ret == -1 {
		err := LastError()
		vol.log.Printf("an error occurred: %v\n", err)
		return err
	}

	vol.log.Println("data set up")

	return nil
}