Home › Forums › .NET libraries › Xceed Zip & Real-Time Zip for .NET › Expected End of Stream not found
-
AuthorPosts
-
#19536 |
I have a CompressionHelper Class which is using NZLib library to Compress the Stream.
using System;
using System.IO;
using NZlib.Compression;
using NZlib.Streams;namespace CompressionClass
{
/// <summary>
/// Summary description for CompressionHelper.
/// </summary>
public class CompressionHelper
{public static Stream GetCompressedStreamCopy(Stream inStream)
{
Stream outStream = new System.IO.MemoryStream();
DeflaterOutputStream compressStream = new DeflaterOutputStream(outStream,
new Deflater(Deflater.BEST_COMPRESSION));byte[] buf = new Byte[1000];
int cnt = inStream.Read(buf,0,1000);
while (cnt>0)
{
compressStream.Write(buf,0,cnt);
cnt = inStream.Read(buf,0,1000);
}
compressStream.Finish();
compressStream.Flush();
return outStream;
}public static Stream GetUncompressedStreamCopy(Stream inStream)
{
return new InflaterInputStream(inStream);
}
}
}How do I Convert this so that I can use Xceed Component to Compress the Stream.
When I tried the Code below, it throws an Exception “Expected End of Stream not found”Any Clues ?
public class CompressionHelper
{public static Stream GetCompressedStreamCopy(Stream inStream)
{
CompressedStream compStream = new CompressedStream( inStream );
return compStream;
}
public static Stream GetUncompressedStreamCopy(Stream inStream)
{
CompressedStream compStream = new CompressedStream( inStream );
return compStream;
}
}Thanks…
Imported from legacy forums. Posted by NETDeveloper (had 2715 views)
I’m not sure I understand exactly what your trying to do.
First, I assume that you’re trying to use Xceed Zip for .NET.
Second, you want to use it instead of the NZlib library, not in conjunction with it.
Third, can you make sure that your inStream is valid.
Fourth, try using the overloaded constructors of the CompressStream class, and see if it works better when specifying the CompressionMethod and the CompressionLevel.
Imported from legacy forums. Posted by Matt (had 3146 views)
hey Team,
I am trying to decompress a compressed stream using XceedCompressedStream.Decompress
but this keeps on showing an error regarding either end of stream or checksum error
PLease help me out with this. I really need a solution
here is my codefor server :
using Xceed.Compression;
using Xceed.Compression.Formats;
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Configuration;
using XceedZipLib;namespace FileSystemDocumentationExamples.CompressionComponent
{
public class DecompressXceedCompressedStreamExample
{
private static void printHex(string Header, byte[] buffer)
{
StringBuilder hex = new StringBuilder(buffer.Length * 2);
foreach (byte b in buffer)
{
hex.AppendFormat(“{0:x2} “, b);
}
Console.WriteLine(“** ” + Header + ” **”);
Console.WriteLine(hex);
}public static void Main(string[] args)
{//StreamWriter writer = new StreamWriter(“D:\\Exception\\new.txt”);
//Console.SetOut(writer);
Xceed.Zip.ReaderWriter.Licenser.LicenseKey =”ZRT61-24AWA-8UKJY-ZBUA”;
Xceed.Compression.Formats.Licenser.LicenseKey =”ZIN61-X4A1A-HUKEY-8BBA”;IPAddress ipAd = IPAddress.Parse(“127.0.0.1″);
TcpListener serverSocket = new TcpListener(ipAd, 8001);
TcpClient clientSocket = default(TcpClient);
serverSocket.Start();Console.WriteLine(” >> Server Started”);
clientSocket = serverSocket.AcceptTcpClient();
Console.WriteLine(” >> Accept connection from client”);
NetworkStream networkStream = clientSocket.GetStream();
MemoryStream ms=new MemoryStream();
byte[] bytesFrom = new byte[78];
int bytesread = 0;try
{
if (networkStream.CanRead)
{bytesread = networkStream.Read(bytesFrom, 0, bytesFrom.Length);
printHex(“Hex Before “,bytesFrom);
Console.WriteLine(“Bytes read : ” + bytesread);
File.WriteAllBytes(@”D:\Exception\MCX.Bin”, bytesFrom);
//networkStream.Flush();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
System.IO.File.WriteAllText(@”D:\Exception\exceptions.txt”, ex.ToString());}
byte[] uncompressedData = new Byte[78];
byte[] buffer = new byte[80];
int bRead = bytesread;buffer = bytesFrom;
int k = 0;try
{
uncompressedData = XceedCompressedStream.Decompress(buffer, 0, 78);
}
catch (Exception E)
{
Console.WriteLine(E.Message);
}k = uncompressedData.Length;
Console.WriteLine(“total number of bytes readed” + k);
networkStream.Write(uncompressedData, 0, bRead);clientSocket.Close();
serverSocket.Stop();
Console.ReadLine();}
}
}for client :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.IO;namespace sendingBinfiledata
{
class Program
{
static void Main(string[] args)
{
System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
using (TcpClient tcpClient = new TcpClient(“127.0.0.1″, 8001))
{
using (NetworkStream networkStream = tcpClient.GetStream())
{
FileStream fs = new FileStream(@”D:\mi.txt”, FileMode.Open, FileAccess.Read);
byte[] dataToSend = new byte[fs.Length];
int k= fs.Read(dataToSend, 0, System.Convert.ToInt32(fs.Length));Console.WriteLine(“byte sent” + k);
//byte[] dataToSend = File.ReadAllBytes(@”D:\mi.txt”);//byte[] dataToSend = {0x00,0x33,0x30,0x30,0x32,0x31,0x0e,0x2c,0x64,0x8d,0xb0,0xab,0x64,0x00,0x83,0xcf,0x0c,0x3c,0x0c,0x0c,0x51,0x1a,0xcc,0x0c,0x7e,0x4c,0x0c,0x43,0x0e,0x5c,0x6a,0xe2,0x22,0x52,0x25,0x00,0x02,0x06,0x2b,0x83};
networkStream.Write(dataToSend,0,dataToSend.Length);
StringBuilder hex = new StringBuilder(dataToSend.Length * 2);
foreach (byte b in dataToSend)
hex.AppendFormat(“{0:x2}”,b);Console.WriteLine(hex);
networkStream.Flush();
byte[] inStream = new byte[1024];
Console.WriteLine(“decompressed data”);networkStream.Read(inStream, 0, inStream.Length);
string line = Encoding.UTF8.GetString(inStream);
System.IO.File.WriteAllText(@”D:\Myzip\JAI.txt”, line);
Console.WriteLine(line);
Console.ReadLine();
}
}}
}
}Please can someone help me out with this
-
AuthorPosts
- You must be logged in to reply to this topic.