Zlib compression or decompression stream.
public sealed class ZlibStream : Stream
Public NotInheritable Class ZlibStream
Inherits Stream
public ref class ZlibStream : public Stream sealed
Shows how to use GetUploadStream method to decompress a file and upload to the server.
using System;
using System.IO;
using ComponentPro.Compression;
using ComponentPro.Net;
...
// Create a new class instance.
Ftp client = new Ftp();
// Connect to the FTP server.
client.Connect("192.168.0.211");
// Authenticate.
client.Authenticate("test", "test");
// ...
// Get upload stream for remote file 'compressed.z'.
Stream ostream = client.GetUploadStream("/compressed.z");
// Create new file
FileStream fi = new FileStream("d:\\temp\\uncompressed.dat", FileMode.Open, FileAccess.Read);
// Create a new instance of the ZlibInputStream for the compression.
ZlibStream zs = new ZlibStream(ostream, 9);
byte[] buf = new byte[8192];
int read;
while ((read = fi.Read(buf, 0, 8192)) > 0) // Read from the Zlib stream.
{
zs.Write(buf, 0, read); // And write to the upload stream.
}
zs.Close();
fi.Close();
// ...
// Disconnect.
client.Disconnect();
Imports System.IO
Imports ComponentPro.Compression
Imports ComponentPro.Net
...
' Create a new class instance.
Dim client As New Ftp()
' Connect to the FTP server.
client.Connect("192.168.0.211")
' Authenticate.
client.Authenticate("test", "test")
' ...
' Get upload stream for remote file 'compressed.z'.
Dim ostream As Stream = client.GetUploadStream("/compressed.z")
' Create new file
Dim fi As New FileStream("d:\temp\uncompressed.dat", FileMode.Open, FileAccess.Read)
' Create a new instance of the ZlibInputStream for the compression.
Dim zs As New ZlibStream(ostream, 9)
Dim buf(8191) As Byte
Dim read As Integer
read = fi.Read(buf, 0, 8192)
Do While read > 0 ' Read from the Zlib stream.
zs.Write(buf, 0, read) ' And write to the upload stream.
read = fi.Read(buf, 0, 8192)
Loop
zs.Close()
fi.Close()
' ...
' Disconnect.
client.Disconnect()
ComponentPro.Compression.ComponentPro.Compression.ZlibStream