PackagePart.GetStream().Write help?

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Hello,

Here is the code I am using:
Code: Select all
Private Sub AddToArchive(ByVal zip As Package, ByVal fileToAdd As String)
        Dim uriFileName As String = fileToAdd.Replace(" ", "_")
        Dim zipUri As String = String.Concat("/", IO.Path.GetFileName(uriFileName))
        Dim partUri As New Uri(zipUri, UriKind.Relative)
        Dim contentType As String = Net.Mime.MediaTypeNames.Application.Zip  
        Dim pkgPart As PackagePart = zip.CreatePart(partUri, contentType, CompressionOption.Normal)
        Dim bites As Byte() = File.ReadAllBytes(fileToAdd)
        Dim inf As New FileInfo(zipPath)
        Dim filesize As Integer = inf.Length
        pkgPart.GetStream().Write(bites, filesize, bites.Length)
    End Sub
On the last part of that, I get an error saying, "Buffer of bytes to be written is too small."

I am trying to write a bunch of .class files to a .jar file containing more .class files. When I go and open up the .jar file with 7zip, I notice that all of the .class files that WERE there are now gone.

How can I fix this? Anyone?

~GoodGuy17 :D
User avatar
kolega28
VIP - Donator
VIP - Donator
Posts: 338
Joined: Mon Jan 17, 2011 7:12 pm

I think you are trying to make a minecraft modder :D Anyway, if its a .jar don't put byval zip, put byval jar.
Image
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

kolega28 wrote:
I think you are trying to make a minecraft modder :D Anyway, if its a .jar don't put byval zip, put byval jar.
Doesn't it work all the same? The files DO make it into the .jar, they're just 0 bytes and all the other files are gone.
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Replace the last line with
Code: Select all
pkgPart.GetStream().Write(bites, filesize, bites.Length - 1)
Or
Code: Select all
pkgPart.GetStream().Write(bites, 0, bites.Length - 1)
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

MrAksel wrote:
Replace the last line with
Code: Select all
pkgPart.GetStream().Write(bites, filesize, bites.Length - 1)
Or
Code: Select all
pkgPart.GetStream().Write(bites, 0, bites.Length - 1)
That stopped the error, but it still deleted everything else in the .jar, leaving only a few folders and the .class files we told it to install/inject/import.
5 posts Page 1 of 1
Return to “Coding Help & Support”