Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Strip zip binary data to leave pdf binary data

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

    I receive zip binary encoded data via an xml file. This basically consists of 1 or more pdf’s wrapped in zip binary data.

    I need to be able to strip the contents out without saving this data to a physical zip file, ie. it needs to be done in memory before i save it to my database.

    I am totally stuck and very new to this product.
    Can anyone help?

    Imported from legacy forums. Posted by Gurminder (had 6313 views)

    User (Old forums)
    Member
    Post count: 23064

    I don’t think i’ve made my message very clear. Let me try again.

    I have pdf binary data which has been zipped as binary data. I need to extract the pdf data out of the zip data in memory, so i basically need to be able to unzip binary data without actually saving it as a physical file.

    I am using vb.net.

    I hope that makes it abit more clearer.

    Imported from legacy forums. Posted by Gurminder (had 303 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m not totally sure I fully understand your request. Is the file within a zip archive, or do you receive it as a compressed stream (could still be a file, but not Zip format)?

    If it is a zip file, you can unzip it using the streaming capabilities of Xceed FileSystem, and then manipulate this stream as you require.

    e.g.:
    <code>
    private static void run()
    {
    AbstractFile zip = new DiskFile( @”D:\archive.zip” );
    ZippedFile zippedFile = new ZippedFile( zip, @”\file.pdf” );
    Stream zippedStream = zippedFile.OpenRead();

    //Then you can read the stream as you wish.
    using( Stream unzippedStream = new MemoryStream() )
    {
    byte[] buffer = new byte[ 32768 ];
    int bytesRead = 0;

    while( ( bytesRead = zippedStream.Read( buffer, 0, buffer.Length ) ) > 0 )
    {
    unzippedStream.Write( buffer, 0, bytesRead );
    }
    }
    </code>.

    You can basically do the same if this is compressed data without file formating. Except that you would use the right compressed stream format to start with (<a href=”http://doc.xceedsoft.com/products/XceedFileSystem/StreamingComponent_Introduction_to_the_Xceed.Compression.Formats_namespace.html”>here</a&gt; is more info compressed formats), instead of a DiskFile.

    Imported from legacy forums. Posted by André (had 233 views)

    User (Old forums)
    Member
    Post count: 23064

    i receive it as a compressed stream. please help with code

    Imported from legacy forums. Posted by Gurminder (had 396 views)

    User (Old forums)
    Member
    Post count: 23064

    You can do something like the following, but you still need to know the format the is used to compress the data, and then use the corresponding compressed stream. In this case, I use the CompressedStream, which in fact is a not formatted stream.
    <code>
    private static void run( Stream inCompressedStream )
    {
    using( CompressedStream compressedStream = new CompressedStream( inCompressedStream ) )
    {
    using( Stream uncompressedStream = new MemoryStream() )
    {
    byte[] buffer = new byte[ 32768 ];
    int bytesRead = 0;

    while( ( bytesRead = CompressedStream.Read( buffer, 0, buffer.Length ) ) > 0 )
    {
    uncompressedStream.Write( buffer, 0, bytesRead );
    }
    }
    }
    }
    </code>

    Imported from legacy forums. Posted by André (had 219 views)

    User (Old forums)
    Member
    Post count: 23064

    What is inCompressedStream?
    i think the compression format is ‘deflated’.

    This is my first time using Xceed so it’s all abit shady at the moment.

    Imported from legacy forums. Posted by Gurminder (had 357 views)

    User (Old forums)
    Member
    Post count: 23064

    InCompressedStream is the compress data, which you mentioned you receive as a stream.

    Deflate is a compression algorithm, not a compression format. When decompressing, you don’t need to set it, since the component will identify itself which algorithm the data was compressed with.

    What you need to know is the format that was use to compress the data. Is it a Zip archive or is it data compressed in a certain format, like GZip or ZLib format?

    Imported from legacy forums. Posted by André (had 327 views)

    User (Old forums)
    Member
    Post count: 23064

    i think it’s a zip archive.
    i am using vb.net. Can you help please?

    Imported from legacy forums. Posted by Gurminder (had 498 views)

    User (Old forums)
    Member
    Post count: 23064

    You can take the first code I posted, but simply use a StreamFile instead of a DiskFile for the zip archive.

    e.g. :<code>
    private static void run4( Stream inStream )
    {
    AbstractFile zip = new StreamFile( inStream );
    ZippedFile zippedFile = new ZippedFile( zip, @”\file.pdf” );
    using( Stream zippedStream = zippedFile.OpenRead() )
    {
    //Then you can read the stream as you wish.
    using( Stream unzippedStream = new MemoryStream() )
    {
    byte[] buffer = new byte[ 32768 ];
    int bytesRead = 0;

    while( ( bytesRead = zippedStream.Read( buffer, 0, buffer.Length ) ) > 0 )
    {
    unzippedStream.Write( buffer, 0, bytesRead );
    }
    //use the unzippedStream here to save the PDF to the DB.
    }
    }
    }
    </code>

    Imported from legacy forums. Posted by André (had 6980 views)

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