-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
I'm trying to create an azure function to receive a list of file urls and add them directly to a single zip file stored into a blob storage.
private static async Task Compress(string sourceFileName, string sourceFileUrl)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("AzureWebJobsStorage"));
CloudBlobClient outputClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer outputContainer = outputClient.GetContainerReference("zip-container");
CloudAppendBlob outputBlob = outputContainer.GetAppendBlobReference("Test.zip");
using var httpClient = new HttpClient();
Stream sourceStream = await httpClient.GetStreamAsync(sourceFileUrl);
if (!await outputBlob.ExistsAsync())
{
await outputBlob.CreateOrReplaceAsync();
using var zipStream = new ZipOutputStream(await outputBlob.OpenWriteAsync(false));
zipStream.SetLevel(3);
ZipEntry zipEntry = new(sourceFileName);
zipEntry.DateTime = DateTime.Now;
zipStream.PutNextEntry(zipEntry);
StreamUtils.Copy(sourceStream, zipStream, new byte[4096]);
zipStream.CloseEntry();
}
else
{
ZipFile zipFile = new(await outputBlob.OpenWriteAsync(false)); //Exception: Stream is not seekable
zipFile.BeginUpdate();
CustomStaticDataSource sds = new();
sds.SetStream(sourceStream);
zipFile.Add(sds, sourceFileName);
zipFile.CommitUpdate();
zipFile.Close();
}
}
The problem occurs when adding more files to existing zip blob. When I try to initialize the ZipFile class with the stream it throws the exception 'Stream is not seekable'.
Version of SharpZipLib
- 1.3.3
- .NET 6
Obtained from
- Package installed using NuGet
Metadata
Metadata
Assignees
Labels
No labels