bucfanjeff
asked on
read/write bytes in chunks
I have this code zipping files, directories, subdir/files, etc successfully - almost.
When I get to a large file, I get the error "Arithmetic operation resulted in an overflow". Based on what I've read, my zFileBuffer is larger than As Byte can handle and I need to read and write the bytes in chunks, say 1024. I'm very much a beginner, can someone please help adjust my code to read/write bytes so I don't overload the byte buffer?
Many, many, many thanks.
When I get to a large file, I get the error "Arithmetic operation resulted in an overflow". Based on what I've read, my zFileBuffer is larger than As Byte can handle and I need to read and write the bytes in chunks, say 1024. I'm very much a beginner, can someone please help adjust my code to read/write bytes so I don't overload the byte buffer?
Many, many, many thanks.
Private Sub Zip(ByVal SourceFolder As String, ByVal DestFile As String)
Dim DirFileNames() As String = Directory.GetFiles(SourceFolder, "*", SearchOption.AllDirectories)
Dim objCrc32 As New Crc32()
Dim zipStream As ZipOutputStream
zipStream = New ZipOutputStream(File.Create(DestFile))
zipStream.SetLevel(9)
Dim zFile As String
For Each zFile In DirFileNames
Dim zFileStream As FileStream = File.OpenRead(zFile)
Dim zFileBuffer(zFileStream.Length - 1) As Byte
Dim strSource As Integer = SourceFolder.Length + 1
zFileStream.Read(zFileBuffer, 0, zFileBuffer.Length)
Dim objZipEntry As ZipEntry = New ZipEntry(zFile.Substring(strSource))
objZipEntry.DateTime = DateTime.Now
objZipEntry.Size = zFileStream.Length
zFileStream.Close()
objCrc32.Reset()
objCrc32.Update(zFileBuffer)
objZipEntry.Crc = objCrc32.Value
zipStream.PutNextEntry(objZipEntry)
zipStream.Write(zFileBuffer, 0, zFileBuffer.Length)
Next
zipStream.Finish()
zipStream.Close()
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I tried the one file by itself and got the same error/issue. The zip class is from http://www.icsharpcode.net/OpenSource/SD/Download/. It works well except in this case where I'm overflowing the Byte.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER