Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Converting from SharpZipLib (Compression)

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

    How do I convert the following statements, to use Xceed Compression….

    1. DeflaterOutputStream compressStream = new DeflaterOutputStream(outStream,
    new Deflater(Deflater.BEST_COMPRESSION));
    2. inStream = new InflaterInputStream(inStream);

    any help is greatly appreciated..

    thanks

    S Kumar

    Imported from legacy forums. Posted by SKumars (had 5153 views)

    User (Old forums)
    Member
    Post count: 23064

    1. CompressedStream compressStream =
    new CompressedStream( outStream, CompressionMethod.Deflated, CompressionLevel.Highest );

    2. inStream = new CompressedStream( inStream );

    In short: It’s the same CompressedStream class. If you start reading from it, it decompresses. If you start writing to it, it compresses.

    Imported from legacy forums. Posted by Martin (had 428 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the reply.

    I can compress it well…(1st statement) but it throws an error when I try to decompress it. (2nd statememnt)

    I am using remoting.

    error: UnExpected EOF
    This is the method..if that helps…

    –USING SharpZipLib
    public static Stream GetUncompressedStreamCopy(Stream inStream)
    {
    try
    {
    MemoryStream outStream = new MemoryStream();
    inStream = new InflaterInputStream(inStream);
    byte[] buf = new Byte[1000];
    int cnt = inStream.Read(buf, 0, 1000);

    while(cnt>0)
    {
    outStream.Write(buf,0,cnt);
    //cnt = inStream.Read(buf, 0, 1000);
    }

    outStream.Seek(0, SeekOrigin.Begin);
    return outStream;
    }
    catch(Exception ex)
    {
    string m = ex.Message;
    return null;
    }
    }

    —–USING XCEED COMPRESSION (Which is the desired version)

    public static Stream GetUncompressedStreamCopy(Stream inStream)
    {
    try
    {
    MemoryStream outStream = new MemoryStream();
    //inStream = new InflaterInputStream(inStream);
    Xceed.Compression.CompressedStream compressStream = new CompressedStream(inStream);
    byte[] buf = new Byte[1000];
    //int cnt = inStream.Read(buf, 0, 1000);
    int cnt = inStream.Read(buf, 0, 1000);
    while(cnt>0)
    {
    outStream.Write(buf,0,cnt);
    cnt = inStream.Read(buf, 0, 1000);
    }
    outStream.Seek(0, SeekOrigin.Begin);
    return outStream;
    }
    catch(Exception ex)
    {
    string m = ex.Message;
    return null;
    }
    }

    Thanks

    Imported from legacy forums. Posted by SKumars (had 263 views)

    User (Old forums)
    Member
    Post count: 23064

    You’re creating a CompressedStream named “compressStream”, but you’re still reading from “inStream”.

    By the way, you should always close your streams when done. This is particularly important when compressing, since the CompressedStream is holding data in order to compress better. When you close it, it will finalize this data in the inner stream. If you don’t want the inner stream to get closed too, set the Transient property to true.

    Imported from legacy forums. Posted by Martin (had 534 views)

    User (Old forums)
    Member
    Post count: 23064

    You were right..I was using wrong stream.
    I corrected it.

    But I still get “Expected end of stream not found” error while decompressing the stream.

    Thanks
    –SKumar

    Imported from legacy forums. Posted by SKumars (had 338 views)

    User (Old forums)
    Member
    Post count: 23064

    Let me make myself clear here.

    I am not saying the compression and decompression doesnt work…it works fantastic for
    any stream. But just in this case where I am using .NET remoting, it doesnt decompress well.
    I get the “Expected end of stream not found” error.

    Thanks for your help..

    –Kumar

    Imported from legacy forums. Posted by SKumars (had 359 views)

    User (Old forums)
    Member
    Post count: 23064

    You should probably send an email to support@xceedsoft.com, with a sample application if possible. The forums are a terrible medium for code samples and such.

    Imported from legacy forums. Posted by Martin (had 5837 views)

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