tags:

views:

42

answers:

1

I want to deflate a file using deflate stream.

Below is the code I am using.

using (oZipper = new DeflateStream(outputFile, CompressionMode.Compress))

Where oZipper is a filestream.

When I step into the line of code above (using (oZipper...), an exception is thrown:

Base stream is not writeable, InvalidArgumentException. Parameter: stream (outputFile, which is a filestream).

Any idea why this is? My code seems to be fine and I'm passing in the right stuff.

Thanks

A: 

How did you open the FileStream? It sounds like you've opened it for reading rather than writing.

EDIT: So that this is more of an answer...

GSS was opening a FileOutputStream using File.Create, but then closing the stream before using it to create the DeflateStream. That stopped DeflateStream from writing to the output stream, hence the problem. Removing the call to close solved the issue.

Jon Skeet
I was just looking at the way I opened it. I have this code: FileStream outputFile = File.Create(Path.Combine(DestinationFileName, filepath)); outputFile.Flush(); outputFile.Close();
dotnetdev
I could try to instantiate a new filestream. Will give that a go, now.
dotnetdev
Just get rid of the call to Close
Jon Skeet
(And the call to flush is unnecessary, but it's the close which is causing the problems.)
Jon Skeet
Thanks for that! Did the trick. Being denied access to the folder now but that's another issue... Thanks again.
dotnetdev