DeflateStream.Read() returns zero

G

Guest

I am having trouble with the DeflateStream.Read() method. For some reason
it wants to return Zero.

I have this set of classes:
===================
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;

namespace SSNCDataLoad
{
interface IDataLoadParse
{
void Parse( Stream inStream
,Stream outStream);
}

public class StdParse : IDataLoadParse
{
virtual public void Parse( Stream inStream
,Stream outStream)
{
const int len = 1024;

Byte[] ba = new Byte[len];

for( int i = inStream.Read( ba, 0, len);
i != 0;
i = inStream.Read( ba, 0, len) )
{
outStream.Write( ba, 0, i );
}
}
}

public class InflateParse : StdParse, IDataLoadParse
{
override public void Parse( Stream inStream
,Stream outStream)
{
FileStream fs = new FileStream(@"c:\Starbuck_log.txt", FileMode.Open,
FileAccess.Read, FileShare.Read);
MemoryStream ms = new MemoryStream();
DeflateParse dfs = new DeflateParse();

dfs.Parse( fs, ms );
fs.Close();

ms.Position = 0;
// base.Parse(inStream, Str);
// Str.Seek(0, SeekOrigin.Begin);

DeflateStream dStream = new DeflateStream(ms, CompressionMode.Decompress);

base.Parse( dStream, outStream);
}
}

public class DeflateParse : StdParse, IDataLoadParse
{
override public void Parse(Stream inStream
, Stream outStream)
{
DeflateStream dStream = new DeflateStream(outStream,
CompressionMode.Compress );

base.Parse(inStream, dStream);
}
}

public class BarParse : StdParse, IDataLoadParse
{
public override void Parse(Stream inStream, Stream outStream)
{
FileStream fs1 = new FileStream(@"C:\InFile.xxx", FileMode.Open );
DeflateStream Str = new DeflateStream(fs1, CompressionMode.Decompress);
FileStream Stw = new FileStream(@"C:\InFile.xxx.txt", FileMode.Create);

base.Parse(Str, Stw);

Stw.Close();
Str.Close();
fs1.Close();

}
}
}
===================

My main program connects to an FTP site and trys to download a file. We
then create the appropriate object above and call the Parse() method. The
FtpResponseStream from the FTP connection is passed in as the inputStream. A
FileStream or MemoryStream object is used as the output stream. However for
some reason the Read() method returns zero.

Any Ideas...
 
J

Jon Skeet [C# MVP]

Brent Rogers said:
I am having trouble with the DeflateStream.Read() method. For some reason
it wants to return Zero.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

The set of classes you've given seems to be more than is required, but
you haven't given the use of the class. A complete example would be
very helpful. You may want to provide sample data to be copied to a
local drive in the form of a link to a website.
 
G

Guest

Jon

In preparing my paired down test app, things started working. Don't know
what I did -- very strange

Thank You any way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top