[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 553
  • Last Modified:

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.
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

Open in new window

0
bucfanjeff
Asked:
bucfanjeff
  • 3
  • 2
3 Solutions
 
grayeCommented:
I'm not 100% certain, but I think there is a 4 Gb limit to the size of the file...     How big is the file that's causing the problem?
0
 
bucfanjeffAuthor Commented:
3.41GB - Which for most practical situations would be abnormal. I know it's an overload of the Byte, which is why I have to read/write the file in smaller chunks. I just don't know how...
0
 
grayeCommented:
Try that one large file by itself.... that way we'll know if it's the size of the zip file or the size of that one entry that causing the problem.
BTW:  I don't recognize that Zip class... it's somewhat resembles the J++ class, but not quite
0
 
bucfanjeffAuthor Commented:
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.
0
 
bucfanjeffAuthor Commented:
I was able to do what I wanted to do MUCH easier using DotNetZip.
Thanks for your input.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now