我正在尝试 gzip 并将静态 js 文件上传到 Azure blob,但我最终得到了一个 0 字节的 blob。有人可以告诉我我做错了什么吗?
var filePath = "C:\test.js";
using (var compressed = new MemoryStream()) {
using (var gzip = new GZipStream(compressed, CompressionMode.Compress)) {
var bytes = File.ReadAllBytes(filePath);
gzip.Write(bytes, 0, bytes.Length);
var account = CloudStorageAccount.Parse("...");
var blobClient = new CloudBlobClient(account.BlobEndpoint, account.Credentials);
var blobContainer = blobClient.GetContainerReference("temp");
var blob = blobContainer.GetBlockBlobReference(Path.GetFileName(filePath));
blob.Properties.ContentEncoding = "gzip";
blob.Properties.ContentType = "text/javascript";
blob.Properties.CacheControl = "public, max-age=3600";
blob.UploadFromStream(compressed);
}
}