EldoS | Feel safer!

Software components for data protection, secure storage and transfer

ZIP from MemoryStream

Posted: 09/19/2011 07:33:56
by Vsevolod Ievgiienko (Team)

All memory streams that you create must exist when you call Compress method. So you should remove 'using (Stream buff = new MemoryStream()) ' construction.
Posted: 09/19/2011 08:25:20
by Aaron Cowie (Basic support level)
Joined: 09/19/2011
Posts: 11

Can you give me a clue as to how I would achieve this in a loop.

I cannot use a single Stream.
I cannot use multiple streams of the same name.
Posted: 09/19/2011 08:32:06
by Vsevolod Ievgiienko (Team)

Do not use 'using' construction. zipWriter.Add method saves a reference to a stream. So you can simply replace 'using (Stream buff = new MemoryStream())' with 'Stream buff = new MemoryStream()'.
Posted: 09/19/2011 08:32:29
by Aaron Cowie (Basic support level)
Joined: 09/19/2011
Posts: 11

Yes worked. Thx!!

final code that seems to work (test example)

byte[] output;

// Set the Eldos.com SecureBlackBox Licence Key

SBArcZip.TElZipWriter zipWriter = new SBArcZip.TElZipWriter();
zipWriter.CompressionAlgorithm = SBZipUtils.Unit.ZIP_COMPRESSION_DEFLATE;

using (Stream zipArchiveStream = new MemoryStream())
int i = 0;
foreach (dynamic att in attachments)
Stream buff = new MemoryStream();

byte[] byteArray = Encoding.UTF8.GetBytes(att.FileContent);
buff.Write(byteArray, 0, byteArray.Length);
buff.Position = 0;
zipWriter.Add(buff, "File" + i.ToString() + att.FileName);

if (i > 2)

output = new byte[zipArchiveStream.Length];
zipArchiveStream.Position = 0;
zipArchiveStream.Read(output, 0, (int)zipArchiveStream.Length);

return output;



Topic viewed 3579 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!