【发布时间】:2015-08-13 05:17:05
【问题描述】:
我想知道在将文件发送到 Azure Blob 存储之前压缩文件是否有好处 - 仅用于传输目的。换句话说,在进出 blob 存储时,预压缩文件会使文件传输更快吗?或者这是否会通过使用 gzip 在传输级别自动发生?
【问题讨论】:
我想知道在将文件发送到 Azure Blob 存储之前压缩文件是否有好处 - 仅用于传输目的。换句话说,在进出 blob 存储时,预压缩文件会使文件传输更快吗?或者这是否会通过使用 gzip 在传输级别自动发生?
【问题讨论】:
自 2015 年 8 月 12 日起,Azure blob 存储(安装到 CDN 时)现在支持自动 GZip 压缩。
压缩方法 - 支持的压缩方法是 gzip/deflate/bzip2,必须在 接受编码请求标头。
【讨论】:
更新
我不确定我最初是怎么做的,但我能想到的只是我看错了结果。我能读到的关于 azure 的所有内容(从 MSDN 到代码本身)现在都告诉我 Azure 不支持将 gzip 用于传输目的。我不知道在什么情况下我能够得到以下结果,现在无法重现它们。不用说,我很失望。
(此答案不正确,请参阅上面的更新)答案是否定的,在发送到 blob 存储之前压缩文件对传输速度没有好处。通过打开 Fiddler,您可以看到传输级别自动通过网络压缩内容。下面的截图证实了这一点:
编辑 1 - Gaurav 的快速说明
在代码中返回的字节数组长度为 386803,但网卡只看到 23505 个字节经过,因为它在响应中被 Azure 压缩。我不需要为此做任何事情。
这是我用来从 Blob 存储发起请求的代码
public Byte[] Read(string containerName, string filename)
{
CheckContainer(containerName);
Initialize();
// Retrieve reference to a previously created container.
CloudBlobContainer container = _blobClient.GetContainerReference(containerName);
// Retrieve reference to a blob named "photo1.jpg".
CloudBlockBlob blockBlob = container.GetBlockBlobReference(filename);
byte[] buffer;
// Save blob contents to a file.
using (var stream = new MemoryStream())
{
blockBlob.DownloadToStream(stream);
stream.Seek(0, SeekOrigin.Begin);
buffer = new byte[stream.Length];
stream.Read(buffer, 0, (int)stream.Length);
}
return buffer;
}
【讨论】:
Content-Encoding属性设置为GZIP会在发送前自动压缩内容?