我的应用程序接收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