Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET zipping byte array in memory

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

    Hello,

    I am trying to zip a PDF that is stored in a byte array and then save compressed file do disk. I am successfully creating the zip folder and there is a file in that folder but I can not open the file. I think that it may be corrupt. I have included the the code that I am using to zip the PDF.

    I would appreciate any assistance or advice that you may have.

    Thank you.

    Language = C#

    byte[] bPDF;

    string zipFilename = @”O:\PDF\ZIP\” + sStringTools.SubStr(cData, 13, 2) + @”\” + cData + “.zip”;

    MemoryStream stream = new MemoryStream(bPDF);
    try
    {
    StreamFile streamFile = new StreamFile(stream, cData + “.pdf”);

    DiskFile zipFile = new DiskFile(zipFilename);

    ZipArchive archive = new ZipArchive(zipFile);

    archive.DefaultCompressionLevel = CompressionLevel.Normal;

    archive.DefaultCompressionMethod = CompressionMethod.Deflated64;

    streamFile.CopyTo(archive, true);
    }
    finally
    {
    stream.Close();

    stream.Dispose();
    }

    Imported from legacy forums. Posted by Richard (had 2292 views)

    Xceed Support
    Member
    Post count: 5658

    I tested this. Using our FileSystem classes and .NET’s, I created a byte array of a PDF file. After, I pretty much used the same code as you.

    I did not get any exception and I was able to create a zip file. Like you said it, the most plausible hypothesis would be corrupted data.

    <code>
    AbstractFile file = new DiskFile( @”D:\PDFFile.pdf” );
    Stream stream = file.OpenRead();
    BinaryReader br = new BinaryReader( stream );
    byte[] bData = br.ReadBytes( (Int32) br.BaseStream.Length );

    MemoryStream mStream = new MemoryStream( bData );

    AbstractFile streamFile = new StreamFile( mStream, “zip10017.zip” );
    AbstractFile zipFile = new DiskFile( @”D:\Forum10017\zip10017.zip” );

    ZipArchive archive = new ZipArchive( zipFile );

    archive.DefaultCompressionLevel = CompressionLevel.Normal;
    archive.DefaultCompressionMethod = CompressionMethod.Deflated64;

    streamFile.CopyTo( archive, true );
    stream.Close();
    </code>

    Imported from legacy forums. Posted by CharlesB (had 3096 views)

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