我有一个名为notactuallygunzipped.gz
的文件,它是一个纯文本文件,恰好以.gz
结尾,并且实际上并没有被枪杀:
1 foo bar
2 fizz buzz
我将其上传到Azure,如下所示:
az storage blob upload \
--container-name testroot \
--file notactuallygunzipped.gz \
--name "gunzip/notactuallygunzipped.gz"
然后我使用Azure Go SDK到fetch the blob。我期望以字节格式取回1 foo bar
之类的内容,而不是我的
\x1f\x8b\x08\x08\x9d\xfa-Y\x00\x03notactuallygunzipped\x003TH\xcb\xcfWHJ,\xe22RH\xca\xccKWH\xca\xcfK\xe7\x02\x00\xa5\x00\xef\x1e\x16\x00\x00\x00
如果我将文件重命名为plaindata.txt
,它可以正常工作,我得到了我的期望:
'1 foo bar\n2 fizz buzz\n'
Azure会做些什么吗?是自动压缩还是沿着那些线?
答案 0 :(得分:3)
Azure无关紧要。您上传的文件notactuallygunzipped.gz
是一个gzip压缩文件。您可以通过less
命令读取它,默认情况下支持解压缩看起来像纯文本的gzip格式,但如果使用cat
则是二进制格式。因此,您需要通过包compress/gzip
解压缩从Azure Blob存储下载的Blob的字节。
作为参考,这是我的示例代码,使用Go从Azure Blob存储中读取gzip文件。
package main
import (
"compress/gzip"
"fmt"
"io/ioutil"
"github.com/Azure/azure-storage-go"
)
func main() {
accountName := "<your-account-name>"
accountKey := "<your-account-key>"
client, _ := storage.NewBasicClient(accountName, accountKey)
blobClient := client.GetBlobService()
containerName := "mycontainer"
container := blobClient.GetContainerReference(containerName)
flag, _ := container.CreateIfNotExists(nil)
fmt.Println(flag)
blobName := "notactuallygunzipped.gz"
blob := container.GetBlobReference(blobName)
readCloser, _ := blob.Get(nil)
defer readCloser.Close()
zr, _ := gzip.NewReader(readCloser)
content, _ := ioutil.ReadAll(zr)
fmt.Printf("%s", content)
}
希望它有所帮助。
答案 1 :(得分:0)
BLOB - 二进制大对象
内容或文件扩展名无关紧要。来自Azure docs:
Azure Blob存储是一种将非结构化数据存储在其中的服务 云作为对象/ blob。 Blob存储可以存储任何类型的文本或 二进制数据,例如文档,媒体文件或应用程序安装程序。 Blob存储也称为对象存储