Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert binary base 64

Status
Not open for further replies.

beckerm

Programmer
May 3, 2001
2
US
I'm trying to convert a binary file into a base 64 string so that I can put it in an XML file. I'm sure someone has already done this so I'm wondering if there is a nice class or dll out there I can use? Thanks.
 
here is the function i got from the MS knowledge base, in case anyone is interested:
Code:
Function ReadBinData(ByVal strFileName As String) As Variant
    Dim lLen As Long
    Dim iFile As Integer
    Dim arrBytes() As Byte
    Dim lCount As Long
    Dim strOut As String
    
    'Read from disk
    iFile = FreeFile()
    Open strFileName For Binary Access Read As iFile
    lLen = FileLen(strFileName)
    ReDim arrBytes(lLen - 1)
    Get iFile, , arrBytes
    Close iFile
    
    ReadBinData = arrBytes
End Function
so my code is:
Code:
'encode
Set oElement = oDom.createElement("TEST")
oRoot.appendChild oElement
oElement.dataType = "bin.base64"
oElement.nodeTypedValue = ReadBinData(filepath)

'decode
m_Doc.Load xmlfilepath    
Set oNode = m_Doc.selectSingleNode("TEST")
byteArray = oNode.nodeTypedValue

Open outputfile For Binary As #1
Put #1, 1, byteArray
Close #1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top