• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang storage.BlobStorageClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/storage.BlobStorageClient的典型用法代码示例。如果您正苦于以下问题:Golang BlobStorageClient类的具体用法?Golang BlobStorageClient怎么用?Golang BlobStorageClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BlobStorageClient类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: validate

func validate(cli storage.BlobStorageClient, blob string, startByte, endByte int64, data []byte) error {

	url := cli.GetBlobURL(cnt, blob)

	reader, err := cli.GetBlob(cnt, blob)
	if err != nil {
		return fmt.Errorf("Failed to read from %s: %s\n", url, err.Error())
	}

	defer reader.Close()

	dataRead, err := ioutil.ReadAll(reader)

	if err != nil {
		return fmt.Errorf("Failed to read from %s: %s\n", url, err.Error())
	}

	same := true
	for i := startByte; i <= endByte; i++ {
		if data[i] != dataRead[i] {
			same = false
		}
	}

	if !same {
		return fmt.Errorf("Failed to read data properly from %s: %s\n", url, err.Error())
	}

	return nil
}
开发者ID:NiklasGustafsson,项目名称:azure-go-samples,代码行数:30,代码来源:blobs03.go


示例2: putBlockBlob

// PutBlockBlob uploads given stream into a block blob by splitting
// data stream into chunks and uploading as blocks. Commits the block
// list at the end. This is a helper method built on top of PutBlock
// and PutBlockList methods with sequential block ID counting logic.
func putBlockBlob(b storage.BlobStorageClient, container, name string, blob io.Reader, chunkSize int) error {
	if chunkSize <= 0 || chunkSize > storage.MaxBlobBlockSize {
		chunkSize = storage.MaxBlobBlockSize
	}

	chunk := make([]byte, chunkSize)
	n, err := blob.Read(chunk)
	if err != nil && err != io.EOF {
		return err
	}

	blockList := []storage.Block{}

	for blockNum := 0; ; blockNum++ {
		id := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%011d", blockNum)))
		data := chunk[:n]
		err = b.PutBlock(container, name, id, data)
		if err != nil {
			return err
		}

		blockList = append(blockList, storage.Block{id, storage.BlockStatusLatest})

		// Read next block
		n, err = blob.Read(chunk)
		if err != nil && err != io.EOF {
			return err
		}
		if err == io.EOF {
			break
		}
	}

	return b.PutBlockList(container, name, blockList)
}
开发者ID:kolargol,项目名称:packer-azure,代码行数:39,代码来源:communicator.go


示例3: clearPage

func clearPage(cli storage.BlobStorageClient, name string, startByte, endByte int64) error {

	if err := cli.PutPage(cnt, name, startByte, endByte, storage.PageWriteTypeClear, nil); err != nil {
		url := cli.GetBlobURL(cnt, name)
		fmt.Printf("Failed to clear pages of %s: %s\n", url, err.Error())
		return err
	}
	return nil
}
开发者ID:NiklasGustafsson,项目名称:azure-go-samples,代码行数:9,代码来源:blobs03.go


示例4: writePage

func writePage(cli storage.BlobStorageClient, name string, startByte, endByte int64, chunk []byte) error {

	if err := cli.PutPage(cnt, name, startByte, endByte, storage.PageWriteTypeUpdate, chunk); err != nil {
		url := cli.GetBlobURL(cnt, name)
		fmt.Printf("Failed to write pages to %s: %s\n", url, err.Error())
		return err
	}
	return nil
}
开发者ID:NiklasGustafsson,项目名称:azure-go-samples,代码行数:9,代码来源:blobs03.go


示例5: resourceArmStorageBlobPageUploadFromSource

func resourceArmStorageBlobPageUploadFromSource(container, name, source string, client *storage.BlobStorageClient, parallelism, attempts int) error {
	workerCount := parallelism * runtime.NumCPU()

	file, err := os.Open(source)
	if err != nil {
		return fmt.Errorf("Error opening source file for upload %q: %s", source, err)
	}
	defer file.Close()

	blobSize, pageList, err := resourceArmStorageBlobPageSplit(file)
	if err != nil {
		return fmt.Errorf("Error splitting source file %q into pages: %s", source, err)
	}

	if err := client.PutPageBlob(container, name, blobSize, map[string]string{}); err != nil {
		return fmt.Errorf("Error creating storage blob on Azure: %s", err)
	}

	pages := make(chan resourceArmStorageBlobPage, len(pageList))
	errors := make(chan error, len(pageList))
	wg := &sync.WaitGroup{}
	wg.Add(len(pageList))

	total := int64(0)
	for _, page := range pageList {
		total += page.section.Size()
		pages <- page
	}
	close(pages)

	for i := 0; i < workerCount; i++ {
		go resourceArmStorageBlobPageUploadWorker(resourceArmStorageBlobPageUploadContext{
			container: container,
			name:      name,
			source:    source,
			blobSize:  blobSize,
			client:    client,
			pages:     pages,
			errors:    errors,
			wg:        wg,
			attempts:  attempts,
		})
	}

	wg.Wait()

	if len(errors) > 0 {
		return fmt.Errorf("Error while uploading source file %q: %s", source, <-errors)
	}

	return nil
}
开发者ID:Originate,项目名称:terraform,代码行数:52,代码来源:resource_arm_storage_blob.go


示例6: resourceArmStorageBlobBlockUploadFromSource

func resourceArmStorageBlobBlockUploadFromSource(container, name, source string, client *storage.BlobStorageClient, parallelism, attempts int) error {
	workerCount := parallelism * runtime.NumCPU()

	file, err := os.Open(source)
	if err != nil {
		return fmt.Errorf("Error opening source file for upload %q: %s", source, err)
	}
	defer file.Close()

	blockList, parts, err := resourceArmStorageBlobBlockSplit(file)
	if err != nil {
		return fmt.Errorf("Error reading and splitting source file for upload %q: %s", source, err)
	}

	wg := &sync.WaitGroup{}
	blocks := make(chan resourceArmStorageBlobBlock, len(parts))
	errors := make(chan error, len(parts))

	wg.Add(len(parts))
	for _, p := range parts {
		blocks <- p
	}
	close(blocks)

	for i := 0; i < workerCount; i++ {
		go resourceArmStorageBlobBlockUploadWorker(resourceArmStorageBlobBlockUploadContext{
			client:    client,
			source:    source,
			container: container,
			name:      name,
			blocks:    blocks,
			errors:    errors,
			wg:        wg,
			attempts:  attempts,
		})
	}

	wg.Wait()

	if len(errors) > 0 {
		return fmt.Errorf("Error while uploading source file %q: %s", source, <-errors)
	}

	err = client.PutBlockList(container, name, blockList)
	if err != nil {
		return fmt.Errorf("Error updating block list for source file %q: %s", source, err)
	}

	return nil
}
开发者ID:Originate,项目名称:terraform,代码行数:50,代码来源:resource_arm_storage_blob.go


示例7: createBlockBlob

func createBlockBlob(cli storage.BlobStorageClient, k string, b []byte) error {
	var err error
	if c.Conf.GZIP {
		if b, err = gz(b); err != nil {
			return err
		}
		k = k + ".gz"
	}

	if err := cli.CreateBlockBlobFromReader(
		c.Conf.AzureContainer,
		k,
		uint64(len(b)),
		bytes.NewReader(b),
		map[string]string{},
	); err != nil {
		return fmt.Errorf("Failed to upload data to %s/%s, %s",
			c.Conf.AzureContainer, k, err)
	}
	return nil
}
开发者ID:ymomoi,项目名称:vuls,代码行数:21,代码来源:azureblob.go



注:本文中的github.com/Azure/azure-sdk-for-go/storage.BlobStorageClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang winterm.GetConsoleMode函数代码示例发布时间:2022-05-24
下一篇:
Golang storage.NewBasicClient函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap