我的應用程序接收PDF格式爲x64文件中的base64,zLib壓縮字符串。至少這是我告訴它的格式。它存儲在數據庫中,然後我需要從該字符串重新創建PDF。我創建了一個測試應用程序來弄清楚。下面的函數需要字符串,並且應該以解碼的,充氣的格式返回它,我相信我可以使用它來重建原始PDF(我還沒有)。麻煩膨脹base64字符串:zlib錯誤:-3
我已經做了大量的研究,並找到了一些不同的庫和方法來做到這一點,以及從發送給我的PDF作爲例子的開發人員收到一個Java程序。但是我無法將字符串轉換爲可用的格式。使用ManagedZLib.dll和下面的函數似乎讓我最接近。據調試,我可以告訴,一切工作,直到我嘗試解壓:
zStream.Read(decompressedBytes, 0, decodedBytes.Length - 1)
這會產生一個「zLib錯誤:-3」。我能找到的唯一信息就是'數據錯誤'。網上關於它的信息很少。
任何幫助越過這個錯誤,或不同的/更好的方法來實現我的最終目標的想法,非常感謝。
Public Function DecompressString4(ByVal origString As String) As String
Dim returnString = Nothing
' get the base64 content into String
ManagedZLib.ManagedZLib.Initialize()
'// parse the string into a byte array
Dim b64bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(origString)
Dim decodedBytes() As Byte = Nothing
'decode the byte array into another byte array, but this time of Base 64.
Using ms As New MemoryStream(b64bytes)
Using zStream As New ManagedZLib.Base64Stream(ms, Base64Options.Decode)
ReDim decodedBytes(b64bytes.Length)
zStream.Read(decodedBytes, 0, b64bytes.Length)
End Using
End Using
decmpStrTxtBox.Text = Convert.ToString(decodedBytes)
Dim decompressedBytes() As Byte = Nothing
' inflate the base64 array
Using ms2 As New MemoryStream(decodedBytes)
Using zStream As New ManagedZLib.CompressionStream(ms2, CompressionOptions.Decompress)
'ReDim decompressedBytes(origString.Length)
ReDim decompressedBytes(decodedBytes.Length)
zStream.Read(decompressedBytes, 0, decodedBytes.Length - 1)
End Using
End Using
'write output to a stream
returnString = Convert.ToString(decompressedBytes)
ManagedZLib.ManagedZLib.Terminate()
Return returnString
End Function