- '示例:以二进制数据对文件进行Base64编码和解码,不能是0字节的空文件
- Dim oStream, file, oNode, s
-
- file = "1.txt"
-
- 'base64编码
- Set oStream = CreateObject("ADODB.Stream")
- oStream.Type = 1 'adTypeBinary
- oStream.Mode = 3 'adModeReadWrite
- oStream.Open()
- oStream.LoadFromFile file
- Set oNode = CreateObject("Msxml2.DOMDocument").CreateElement("base64")
- oNode.DataType = "bin.base64"
- oNode.nodeTypedValue = oStream.Read()
- oStream.Close()
- Wsh.Echo oNode.Text
-
- 'base64解码
- s = oNode.Text
- Set oNode = CreateObject("Msxml2.DOMDocument").CreateElement("base64")
- oNode.DataType = "bin.base64"
- oNode.Text = s
- Set oStream = CreateObject("ADODB.Stream")
- oStream.Type = 1 'adTypeBinary
- oStream.Mode = 3 'adModeReadWrite
- oStream.Open()
- oStream.Write oNode.nodeTypedValue
- oStream.SaveToFile file, 2 'adSaveCreateOverWrite
- oStream.Close()
-
- MsgBox "ok"
复制代码
|