Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET This CompressedStream object does not support reading or decompressing.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #20472 |

    Hmmm. Just purchased, so maybe I am missing something. I copied this code out of the StreamDemo project into a VS2010 console app:

    FileStream sourceStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
    FileStream destStream = new FileStream(fileName + “.zip”, FileMode.Create, FileAccess.Write);
    CompressedStream compStream = new CompressedStream(destStream, CompressionMethod.PPMd, CompressionLevel.Normal);
    StreamCopy(compStream, destStream);

    private static void StreamCopy(Stream sourceStream, Stream destStream)
            {
                try
                {
                    int bytesRead;
                    byte[] buffer = new byte[32768];

                    while ((bytesRead = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
                        destStream.Write(buffer, 0, bytesRead);
                }
                finally
                {
                    sourceStream.Close();
                    destStream.Close();
                }
            }

    fileName is a valid XML file. I verified that the file stream is loading the file properly, and there is a zero-byte file being created for destination. However, this line: while ((bytesRead = sourceStream.Read(buffer, 0, buffer.Length)) > 0) raises this error: This CompressedStream object does not support reading or decompressing.

    What am I missing?

    Imported from legacy forums. Posted by Michael (had 1144 views)

    Diane [Xceed]
    Moderator
    Post count: 1353

    Hi Michael,

    I think you did a mistake when copying the code from the StreamDemo project.

    The DoCompress() and DoDecompress() methods in the project are slightly different. The creation of the sourceStream and destStream are the same, but the compStream and the call to StreamCopy are different. You seem to have use the StreamCopy call from DoDecompress() but with the compStream code from DoCompress().

     

    Imported from legacy forums. Posted by Diane [Xceed] (had 308 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your help! I did copy it wrong. [:)]

    Imported from legacy forums. Posted by Michael (had 1105 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.