EnterpriseDT.Net.Zlib is really intended for internal use only. I suggest you use System.IO.Compression.GZipStream instead. Here's an example which uploads a compressed version of the byte-array, uploadData, to the server; downloads it again; decompresses it and puts it into downloadData:
// Set up FTPConnection
FTPConnection connection = new FTPConnection();
connection.ServerAddress = serverAddress;
connection.UserName = userName;
connection.Password = password;
// Connect to server
connection.Connect();
// Compress data into uploadBuffer
MemoryStream uploadBuffer = new MemoryStream();
GZipStream compressor = new GZipStream(uploadBuffer, CompressionMode.Compress, true);
compressor.Write(uploadData, 0, uploadData.Length);
compressor.Dispose();
// upload the uploadBuffer
connection.UploadStream(uploadBuffer, fileName);
// download into downloadBuffer
MemoryStream downloadBuffer = new MemoryStream();
connection.CloseStreamsAfterTransfer = false;
connection.DownloadStream(downloadBuffer, fileName);
// decompress it
downloadBuffer.Seek(0, SeekOrigin.Begin);
GZipStream decompressor = new GZipStream(downloadBuffer, CompressionMode.Decompress);
MemoryStream data = new MemoryStream();
byte[] buffer = new byte[1024];
int numBytes;
while ((numBytes=decompressor.Read(buffer, 0, buffer.Length))>0)
data.Write(buffer, 0, numBytes);
// copy the byte-array into downloadData
downloadData = data.ToArray();
// close the connection
connection.Close();
A few things to note:
- You must call Dispose on the GZipStream when you've finished writing your data to it.
- You must set CloseStreamsAfterTransfer to false before downloading into the stream.
- You must seek back to the beginning of the downloaded stream before reading the data.
- Hans (EnterpriseDT)