Ejemplo n.º 1
0
        private async Task ZipAllFilesToStream(
            Release release,
            Stream outputStream,
            CancellationToken?cancellationToken = null)
        {
            var releaseFiles = (await QueryReleaseFiles(release.Id).ToListAsync())
                               .OrderBy(rf => rf.File.ZipFileEntryName())
                               .ToList();

            var path       = Path.GetTempPath() + release.AllFilesZipFileName();
            var fileStream = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            await using var multiWriteStream = new MultiWriteStream(outputStream, fileStream);

            await DoZipFilesToStream(releaseFiles, release, multiWriteStream, cancellationToken);

            await multiWriteStream.FlushAsync();

            // Now cache the All files zip into blob storage
            // so that we can quickly fetch it again.
            fileStream.Position = 0;

            await _blobStorageService.UploadStream(
                containerName : PublicReleaseFiles,
                path : release.AllFilesZipPath(),
                stream : fileStream,
                contentType : MediaTypeNames.Application.Zip
                );

            await fileStream.DisposeAsync();

            File.Delete(path);
        }
 public static string AllFilesZipPath(this Release release)
 {
     return($"{FilesPath(release.Id, AllFilesZip)}{release.AllFilesZipFileName()}");
 }