[
  {
    "Id": "161608",
    "ThreadId": "48408",
    "Html": "<span lang=EN>\r\n<p>I successfully used Ionic.Zip to create a zipfile and add items to it.  Now I need to use Ionic.ZLib to read a zip stream into a byte array so I can store the .zip file as a binary in the SQL Server database.  When I declare Ionic.ZLib.ZLibStream ,<span style=\"font-size:13px;color:#0000ff\"><span style=\"font-size:13px;color:#0000ff\">\r\n<p>&nbsp;</p>\r\n<p>Dim</p>\r\n</span>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p><span style=\"font-size:13px\"> sZipFile </span><span style=\"font-size:13px;color:#0000ff\">As</span><span style=\"font-size:13px\"> </span><span style=\"font-size:13px;color:#0000ff\">New</span><span style=\"font-size:13px\"> Ionic.Zlib.ZlibStream\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n</span></p>\r\n<p>it says that ZLibStream is ambiguous in the namespace ZLib, and I can't get past that error to write any further code.  I am using VB.NET.  I referenced both Ionic.Lib and Ionic.ZLib in my project.  What am I doing wrong?  Thank you for help.  This is a great library.<br>\r\n<br>\r\nKrystal</p>\r\n</span>\r\n",
    "PostedDate": "2009-02-24T12:48:25.957-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "161636",
    "ThreadId": "48408",
    "Html": "Hey Krystal, thanks for using the forum. <br>\r\n  <br>\r\nHere's some code I worked up to demonstrate the use of the ZlibStream.\r\n<pre>' zlib1.vb\r\n'\r\n' Demonstrate the use of the ZlibStream\r\n'\r\n' Author: Dinoch\r\n' Created: Tue Feb 24 13:21:36 2009\r\n'\r\n' last saved: \r\n' Time-stamp: &lt;2009-February-24 13:46:38&gt;\r\n' ------------------------------------------------------------------\r\n'\r\n' Copyright (c) 2009 by Dino Chiesa\r\n' All rights reserved!\r\n' \r\n' ------------------------------------------------------------------\r\n\r\n\r\nImports System\r\nImports Ionic.Zlib\r\nImports System.IO\r\n\r\nNamespace Ionic.Test.Krystal \r\n\r\n\r\nPublic Class zlib1\r\n\r\n   ' Fields\r\n    Private _CompressedFile As String\r\n    Private _Crc1 As Integer\r\n    Private _Crc2 As Integer\r\n    Private _DecompressedFile As String\r\n    Private _FileToCompress As String\r\n    Private _WantZlib As Boolean\r\n    Private Const WORKING_BUFFER_SIZE As Integer = 4000\r\n\r\n    'ctors\r\n    Public Sub New()\r\n        Me._WantZlib = False\r\n    End Sub\r\n\r\n    Public Sub New(ByVal args As String())\r\n        Me._WantZlib = False\r\n        Dim i As Integer\r\n        For i = 0 To args.Length - 1\r\n            If (Not args(i) Is Nothing) Then\r\n              If (args(i) = &quot;-zlib&quot;) Then\r\n                Me._WantZlib = True\r\n                Continue For\r\n              Else\r\n\t\tIf (Not Me._FileToCompress Is Nothing) Then\r\n\t\t    zlib1.Usage\r\n\t\t    Exit For\r\n\t\tEnd If\r\n                Me._FileToCompress = args(i)\r\n              End If\r\n            End If\r\n        Next i\r\n    End Sub\r\n\r\n    ' Methods\r\n\r\n    Private Sub CompressFile()\r\n        Me._Crc1 = Me.DoCrc(Me._FileToCompress)\r\n        Me._CompressedFile = (Me._FileToCompress &amp; &quot;.compressed&quot;)\r\n\tIf Not Me._CompressedFile.StartsWith(&quot;unpack\\&quot;) Then\r\n\t    Me._CompressedFile = Path.Combine(&quot;unpack&quot;, Me._CompressedFile)\r\n\tEnd If\r\n\tIf Not Directory.Exists(&quot;unpack&quot;) Then\r\n\t    Directory.CreateDirectory(&quot;unpack&quot;)\r\n\tEnd If\r\n\tConsole.WriteLine(ChrW(10) &amp; &quot;Creating compressed file: {0}&quot;, Me._CompressedFile)\r\n        Using input As Stream = File.OpenRead(Me._FileToCompress)\r\n            Using raw As FileStream = File.Create(Me._CompressedFile)\r\n                Dim compressor As Stream = Nothing\r\n                Try\r\n                    if Me._WantZlib Then\r\n                      compressor = New ZlibStream(raw, CompressionMode.Compress, True)\r\n                    Else\r\n                      compressor = New DeflateStream(raw, CompressionMode.Compress, True)\r\n                    End If\r\n                    Console.WriteLine(&quot;Using {0} to compress...&quot;, compressor.GetType.FullName)\r\n                    Dim working As Byte() = New Byte(WORKING_BUFFER_SIZE ) {}\r\n                    Dim n As Integer = -1\r\n                    Do While (n &lt;&gt; 0)\r\n                        If (n &gt; 0) Then\r\n                            compressor.Write(working, 0, n)\r\n                        End If\r\n                        n = input.Read(working, 0, working.Length)\r\n                    Loop\r\n                Finally\r\n                  If Not compressor Is Nothing Then\r\n                      compressor.Dispose()\r\n                  End If\r\n                End Try\r\n            End Using\r\n        End Using\r\n    End Sub\r\n\r\n\r\n    Private Sub DecompressFile()\r\n        Dim working As Byte() = New Byte(WORKING_BUFFER_SIZE) {}\r\n        Dim n As Integer = -7\r\n        Using s1 As Stream = File.OpenRead(Me._CompressedFile)\r\n            Me._DecompressedFile = (Me._CompressedFile &amp; &quot;.decompressed&quot;)\r\n            Console.WriteLine(ChrW(10) &amp; &quot;Creating decompressed file: {0}&quot;, Me._CompressedFile)\r\n            Dim decompressor As Stream = Nothing\r\n            Try \r\n                If Me._WantZlib Then\r\n                    decompressor = New ZlibStream(s1, CompressionMode.Decompress, True)\r\n                Else\r\n                    decompressor = New DeflateStream(s1, CompressionMode.Decompress, True)\r\n                End If\r\n                Console.WriteLine(&quot;Using {0} to decompress...&quot;, decompressor.GetType.FullName)\r\n                Using s2 As FileStream = File.Create(Me._DecompressedFile)\r\n                    Do While ((n &lt;&gt; 0) AndAlso (n &lt;&gt; -1))\r\n                        n = decompressor.Read(working, 0, working.Length)\r\n                        Console.WriteLine(&quot;read {0} bytes&quot;, n)\r\n                        If (n &gt; 0) Then\r\n                            s2.Write(working, 0, n)\r\n                        End If\r\n                    Loop\r\n                End Using\r\n\t    Finally\r\n\t      If Not decompressor Is Nothing Then\r\n\t\t  decompressor.Dispose()\r\n\t      End If\r\n            End Try\r\n        End Using\r\n        Me._Crc2 = Me.DoCrc(Me._DecompressedFile)\r\n    End Sub\r\n\r\n\r\n    Private Function DoCrc(ByVal filename As String) As Integer\r\n        Dim working As Byte() = New Byte(WORKING_BUFFER_SIZE) {}\r\n        Dim n As Integer = -1\r\n        Dim result As Integer = 0\r\n        Using a As Stream = File.OpenRead(filename)\r\n            Using b As  New Ionic.Zip.CrcCalculatorStream(a)\r\n                n = -1\r\n                Do While (n &lt;&gt; 0)\r\n                    n = b.Read(working, 0, working.Length)\r\n                Loop\r\n                Console.WriteLine(&quot;File:{0}  CRC32:0x{1:X8}&quot;, filename, b.Crc32)\r\n                result = b.Crc32\r\n            End Using\r\n        End Using\r\n        Return result\r\n    End Function\r\n\r\n\r\n    Public Sub Run()\r\n        If (Me._FileToCompress Is Nothing) Then\r\n            zlib1.Usage\r\n        Else\r\n            Me.CompressFile\r\n            Me.DecompressFile\r\n            If (Me._Crc1 = Me._Crc2) Then\r\n                Console.WriteLine(&quot;The files match.&quot;)\r\n            Else\r\n                Console.WriteLine(&quot;The files DO NOT MATCH.&quot;)\r\n            End If\r\n        End If\r\n    End Sub\r\n\r\n\r\n\r\n    Public Shared Sub Main(ByVal args As String())\r\n        Try \r\n\t    Dim z as New zlib1(args)\r\n            z.Run\r\n        Catch exc1 As Exception\r\n            Console.WriteLine(&quot;Exception: {0}&quot;, exc1.ToString)\r\n            zlib1.Usage\r\n        End Try\r\n    End Sub\r\n\r\n\r\n   Public Shared Sub Usage()\r\n        Console.WriteLine(&quot;ZlibTest: compress a file using DeflateStream or ZlibStream.&quot; &amp; ChrW(10))\r\n        Console.WriteLine(&quot;Usage:&quot; &amp; ChrW(10) &amp; &quot;  ZlibTest [-zlib] &lt;filetodeflate /&gt;&quot;)\r\n        Console.WriteLine(&quot;    -zlib  == use ZlibStream instead of DeflateStream.&quot;)\r\n    End Sub\r\n\r\nEnd Class\r\n\r\n \r\nEnd Namespace\r\n\r\n</pre>\r\n",
    "PostedDate": "2009-02-24T13:59:34.023-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "161639",
    "ThreadId": "48408",
    "Html": "Krystal, I think I answered the question (&quot;How to use ZlibStream from VB.NET?&quot;)  but I didn't really answer the question &quot;What am I doing wrong?&quot; <br>\r\n<br>\r\nYou said you wanted to load the ZIP file into SQL Server.  You DO NOT need a ZlibStream to do that, in fact I think you may be on the wrong track there. <br>\r\nThe ZlibStream is a stream class that slurps in uncompressed data and spits out compressed data.  It is a lower-level class, not typically something you would use if you are creating and manipulating ZIP files. <br>\r\nThe ZipFile class within DotNetZip uses the ZlibStream (actually the cousin, the DeflateStream), to compress the filedata that it inserts into a zip file.  But if you are creating a zip file, you would never need to directly interact with ZlibStream class or the DeflateStream class. <br>\r\n<br>\r\nIf what you want is to load a byte array into SQL Server, and the byte array should contain the contents of the zip file, then you have a couple options. <br>\r\n1. Create the zip file as normal, save it to a file on disk.  Then, read in the file from the disk, into a byte array in memory.  You would use System.IO.File.OpenRead() to do that, then read in all the data.  Then do your thing with SQL.  (I'll assume you know how to load a byte array / blob into SQL)<br>\r\n2. Create the zip file ALMOST as normal, but save it to a MemoryStream, which you can then easily convert into a byte array. Instead of calling ZipFile.Save() with the name of an on-disk file, call ZipFile.Save() with a MemoryStream object.<br>\r\n<br>\r\nI don't believe, from your english description of what you want to accomplish, that you need the ZlibStream class.  <br>\r\n<br>\r\n<br>\r\n",
    "PostedDate": "2009-02-24T14:07:56.67-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "161649",
    "ThreadId": "48408",
    "Html": "Thank you for your help, Cheeso.  That's great that I can skip Zlib and just use the regular lib.  Thanks for the help with the two options for storing into SQL Server.<br>\r\n<br>\r\nKrystal\r\n",
    "PostedDate": "2009-02-24T14:16:06.66-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]