Saving to non-seekable stream

Aug 29, 2010 at 5: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())



The problem is, I get an exception that the stream does not support seeking. Reading the documentation at

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

Thanks for any help you can offer.

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