Question:
I am using the 32 bit version 9.5.0.48 of the zip component for .net 3.5. I have a linkbutton on a site when clicked will create a zip file in memory and download it to the user. This issue seems to happen when compressing very large files. The one I am testing has 750 MB in files. It does not always successfully compress the zip file. Most times it throws either a "specified argument was out of the range of valid values parameter name offset" error or "System.OutOfMemory" exception.
Here's the .net code i am using:
Protected Sub btnZip_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnZip.Click
If Page.IsPostBack Then
Dim iAppID As Integer = 0
litMessage.Text = ""
Try
If Not Request.Params("edit") Is Nothing Then
If IsNumeric(Request.Params("edit")) Then
iAppID = Request.Params("edit")
End If
End If
Catch ex As Exception
iAppID = 0
End Try
Dim zip As New Chilkat.Zip()
Dim success As Boolean
success = zip.UnlockComponent("<key>")
If (success <> True) Then
'MsgBox("Failed to unlock zip component")
Response.Write("Failed to unlock zip component")
Exit Sub
End If
' NewZip initializes the zip object. It does not write
' the file. The "test.zip" file, in this case, will never be written.
Dim dDate As Date = Date.Today
Dim sFileName As String = "App-" & iAppID.ToString & "_" & Format(dDate, "MMM-dd-yyyy")
success = zip.NewZip(sFileName & ".zip")
If (success <> True) Then
'MsgBox(zip.LastErrorText)
Response.Write(zip.LastErrorText)
Exit Sub
End If
Dim oData As Data.DataSet
Dim sFilePath As String = Application("PerformerApplication")
sFilePath &= hidAppYear.Value & "/" & hidStatID.Value & "/"
oData = Applications.GetMappedFiles(hidPerfAppID.Value)
For Each oRow As Data.DataRow In oData.Tables(0).Rows
If System.IO.File.Exists(sFilePath & oRow("FileName").ToString) = True Then
success = zip.AppendOneFileOrDir(sFilePath & oRow("FileName").ToString, False)
Dim entry As Chilkat.ZipEntry
Dim sNewFileName As String = oRow("OriginalFileName").ToString.Replace(" ", "_")
'Dim fFile As System.IO.FileInfo = New System.IO.FileInfo(sFilePath & oRow("FileName").ToString)
entry = zip.GetEntryByName(oRow("FileName").ToString)
If (entry Is Nothing) Then
litMessage.Text = ConjunctionJunction.WriteMessageBox("Problem: Failed to find entry in .zip")
Exit Sub
End If
'Dim sTestName As String = ""
entry.FileName = sNewFileName '& fFile.Extension.ToLower
Else
litMessage.Text = ConjunctionJunction.WriteMessageBox("Problem: All the files are not found. Download aborted.")
Exit Sub
End If
Next
oData = Nothing
Dim Data As Byte()
Data = zip.WriteToMemory
'binarywrite specified argument was out of the range of valid values parameter name offset
If Data.Length > 0 Then
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Length", Data.Length.ToString())
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & zip.FileName & """")
Response.Flush()
Response.BinaryWrite(Data)
Else
SendChilkatError(zip.LastErrorText)
litMessage.Text = ConjunctionJunction.WriteMessageBox("Problem: Issue creating the zip file. Download aborted.")
Exit Sub
End If
End If
End Sub
Here is the last error log:
ChilkatLog:
WriteToMemory:
DllDate: Mar 6 2015
ChilkatVersion: 9.5.0.48
UnlockPrefix: hiddenCode
Username: PC
Architecture: Little Endian; 32-bit
Language: .NET 2.0
VerboseLogging: 0
targetZipPath: App-98_Mar-18-2015.zip
writeZipToOutput:
oemCodePage: 437
encryption: 0
passwordProtected: 0
totalSize64: 835371467
file_writeLfhAndData:
zipSourceEntry:
Failed to allocate memory for output data buffer.
ensureSz0: 199790978
ensureSz: 299686467
m_idx: 199759896
size: 31074
Failed to write compressed data to output file.
Deflate source to output failed.
--zipSourceEntry
--file_writeLfhAndData
Output failed.
--writeZipToOutput
Failed.
I am not sure how to resolve this issue.
I think the only solution is to write the .zip to a temp file on the server and then stream the response from the temp file. After streaming the response, you may delete the temp file.
I found this information after Googling (not expecting to find a Chilkat-specific result, but found something I wrote a few years back..)
http://www.chilkatsoft.com/p/p_271.asp
The information at the URL above mentions a separate FileAccess ActiveX DLL, but the FileAccess class/object is included within the Chilkat ActiveX DLL nowadays..