private async Task UploadEntry(ZipArchiveEntry entry, S3WriterResourceProperties properties) { // unzip entry using (var stream = entry.Open()) { var memoryStream = new MemoryStream(); // determine if stream needs to be encoded string contentEncodingHeader = null; var encoding = DetermineEncodingType(entry.FullName, properties); switch (encoding) { case "NONE": await stream.CopyToAsync(memoryStream); break; case "GZIP": contentEncodingHeader = "gzip"; using (var gzipStream = new GZipStream(memoryStream, CompressionLevel.Optimal, leaveOpen: true)) { await stream.CopyToAsync(gzipStream); } break; case "BROTLI": contentEncodingHeader = "br"; using (var brotliStream = new BrotliStream(memoryStream, CompressionLevel.Optimal, leaveOpen: true)) { await stream.CopyToAsync(brotliStream); } break; default: _logger.LogWarn("unrecognized compression type {0} for {1}", encoding, entry.FullName); encoding = "NONE"; goto case "NONE"; } var base64 = GetMD5AsBase64(memoryStream); // only upload file if new or the contents have changed var destination = Path.Combine(properties.DestinationKey, entry.FullName).Replace('\\', '/'); _logger.LogInfo($"uploading file: {destination} [encoding: {encoding.ToLowerInvariant()}]"); await _transferUtility.UploadAsync(new TransferUtilityUploadRequest { Headers = { ContentEncoding = contentEncodingHeader, ContentMD5 = base64 }, InputStream = memoryStream, BucketName = properties.DestinationBucket, Key = destination }); } }