Saving to non-seekable stream

Aug 29, 2010 at 6:54 PM

I am attempting to create an encrypted zip with a 3rd party crypto library. I've reduced the problem down to a simple example. I am attempting to add a directory and save it to a CryptoStream, but it fails with the CountingStream ctor, because Position is not available to a CryptoStream. Basically:

using (ICryptoTransform encryptor = _ctx.Algorithm.CreateEncryptor())
using (FileStream outputStream = GetWriteableFileStream(_outputFilename))
using (CryptoStream cryptoStream = GetWriteCryptoStream(outputStream, encryptor))
{
     using (ZipFile zip = new ZipFile())
     {
          zip.AddDirectory(_directory);

          zip.Save(cryptoStream);
     }

}

The problem is, I get an exception that the stream does not support seeking. Reading the documentation at http://cheeso.members.winisp.net/DotNetZipHelp/html/8b981f77-742a-5f47-6299-c27104871d8c.htm

suggests that this is possible. Should CountingStream check Stream.CanSeek before trying to read Stream.Position?

Thanks for any help you can offer.

Coordinator
Aug 31, 2010 at 1:29 PM
Sounds plausible. I thought I handled that case, but it's possible I did not. I'll have a look.