Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.scripting.vbscript > #12234
| From | Schmidt <ng@vbRichClient.com> |
|---|---|
| Newsgroups | microsoft.public.scripting.vbscript |
| Subject | Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used |
| Date | 2019-09-22 16:32 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <qm80ls$8cd$1@dont-email.me> (permalink) |
| References | <oslw59d5yyzg.lp5zzahpop8v.dlg@40tude.net> <qm3a6i$po8$1@dont-email.me> <qm3fc9$nof$1@dont-email.me> <qm3j85$egp$1@dont-email.me> <qm46ns$1g2$1@dont-email.me> |
Am 21.09.2019 um 05:50 schrieb Mayayana:
> I turned this into a finished script ...
I'd leave the generic Helper-Functions I've posted intact
(one can place them in - and later load them from an include-file)
With just the two additional Helpers I've mentioned
(StringToBytes and BytesToString) you'd have all you need,
to replicate your Script with this short(er) code:
'*** script-code ***
Dim File, T, bInp, sB64
File = WScript.Arguments(0)
If MsgBox("Click yes to encode (no to decode)", vbYesNo) = vbYes Then
T = Timer
bInp = ReadBytesFromFile(File)
sB64 = Base64Encode(bInp)
WriteBytesToFile File & "-64.txt", StringToBytes(sB64, "utf-8")
Else
T = Timer
bInp = ReadBytesFromFile(File)
sB64 = BytesToString(bInp, "utf-8")
WriteBytesToFile File & "-64.dat", Base64Decode(sB64)
End If
MsgBox Timer - T
'*** end of script-code ***
Ok, here again the helper-stuff (now including StringToBytes/BytesToString):
'******* a small set of generic Helper-Functions *******
'* (usually placed in and loaded from an Include-File) *
Function BytesToString(Bytes, Charset)
With CreateObject("ADODB.Stream")
.Open
.Charset = Charset
.Type = 1: .Write Bytes: .Position = 0
.Type = 2
Do Until .EOS
BytesToString = BytesToString & .ReadText(2^18)
Loop
.Close
End With
End Function
Function StringToBytes(S, Charset)
With CreateObject("ADODB.Stream")
.Open
.Charset = Charset
.Type = 2: .WriteText S: .Position = 0
.Type = 1
If LCase(Charset) = "utf-8" Then .Position = 3
StringToBytes = .Read
.Close
End With
End Function
Function Base64Encode(Bytes) 'expects VarType "Byte()", returns a B64-String
With CreateObject("Msxml2.DOMDocument").CreateElement("e")
.DataType = "bin.base64"
.NodeTypedValue = Bytes
Base64Encode = .Text
End With
End Function
Function Base64Decode(sBase64) 'expects a B64-String, returns VarType
"Byte()"
With CreateObject("Msxml2.DOMDocument").CreateElement("e")
.DataType = "bin.base64"
.Text = sBase64
Base64Decode = .NodeTypedValue
End With
End Function
Function ReadBytesFromFile(FileName) 'returns VarType "Byte()"
With CreateObject("ADODB.Stream")
.Open
.Type = 1 'adTypeBinary
.LoadFromFile FileName
ReadBytesFromFile = .Read
.Close
End With
End Function
Sub WriteBytesToFile(FileName, Bytes) 'expects VarType "Byte()"
With CreateObject("ADODB.Stream")
.Open
.Type = 1 'adTypeBinary
.Write Bytes
.SaveToFile FileName, 2 'adSaveCreateOverWrite
.Close
End With
End Sub
'*** end of generic script-helpers ***
HTH
Olaf
Back to microsoft.public.scripting.vbscript | Previous | Next — Previous in thread | Next in thread | Find similar
ADODB.Stream binary array to binary string failed unless x-user-defined is used JJ <jj4public@vfemail.net> - 2019-09-16 08:23 +0700
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-15 23:03 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used GS <gs@v.invalid> - 2019-09-15 23:58 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-16 10:08 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used GS <gs@v.invalid> - 2019-09-16 12:32 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-16 13:13 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used GS <gs@v.invalid> - 2019-09-16 20:26 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-16 22:08 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used GS <gs@v.invalid> - 2019-09-17 22:08 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used JJ <jj4public@vfemail.net> - 2019-09-16 18:27 +0700
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-16 09:55 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-16 10:32 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used JJ <jj4public@vfemail.net> - 2019-09-17 20:15 +0700
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-17 10:04 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-17 23:04 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used JJ <jj4public@vfemail.net> - 2019-09-18 16:17 +0700
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-18 10:12 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used JJ <jj4public@vfemail.net> - 2019-09-19 21:23 +0700
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-19 11:47 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "R.Wieser" <address@not.available> - 2019-09-18 11:30 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used JJ <jj4public@vfemail.net> - 2019-09-18 17:43 +0700
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-18 10:16 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "R.Wieser" <address@not.available> - 2019-09-18 16:49 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-19 09:29 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "R.Wieser" <address@not.available> - 2019-09-19 20:10 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "R.Wieser" <address@not.available> - 2019-09-20 08:04 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used JJ <jj4public@vfemail.net> - 2019-09-20 16:06 +0700
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "R.Wieser" <address@not.available> - 2019-09-22 12:15 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-22 09:38 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "R.Wieser" <address@not.available> - 2019-09-22 16:49 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-16 15:58 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used Schmidt <ng@vbRichClient.com> - 2019-09-20 21:44 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-20 17:11 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used Schmidt <ng@vbRichClient.com> - 2019-09-21 00:18 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-20 21:26 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-20 23:50 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used Schmidt <ng@vbRichClient.com> - 2019-09-22 16:32 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-22 12:45 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used Schmidt <ng@vbRichClient.com> - 2019-09-22 19:41 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-22 14:10 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used Schmidt <ng@vbRichClient.com> - 2019-09-22 20:46 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-22 15:09 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used Schmidt <ng@vbRichClient.com> - 2019-09-22 22:30 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-22 15:10 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used Schmidt <ng@vbRichClient.com> - 2019-09-22 22:32 +0200
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used "Mayayana" <mayayana@invalid.nospam> - 2019-09-22 13:45 -0400
Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used JJ <jj4public@vfemail.net> - 2019-09-22 02:07 +0700
csiph-web