Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #12196

Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used

From "Mayayana" <mayayana@invalid.nospam>
Newsgroups microsoft.public.scripting.vbscript
Subject Re: ADODB.Stream binary array to binary string failed unless x-user-defined is used
Date 2019-09-16 15:58 -0400
Organization A noiseless patient Spider
Message-ID <qlopj6$r2s$1@dont-email.me> (permalink)
References <oslw59d5yyzg.lp5zzahpop8v.dlg@40tude.net>

Show all headers | View raw


   The following seems to work, but I got to fooling around
and now I'm not sure what I did right. :) It looks like the only
difference was in changing the CharSet value, but I thought
I'd tried that before and it didn't work. In any case, this code
seems to work now. On a 3.6 MB file it was very quick to encode.
.17 seconds. But oddly slow to decode. 5.5 seconds. It also works
fine on your sample.

    So it may have only been a problem with using ascii as
CharSet. It didn't matter to the original author because he
only wanted to encode English text. Though I don't understand
why you couldn't use your "x-user-defined". In any case,
Windows-1252 works, as should any other ANSI encoding.


Dim LRet, Arg, FSO, TS, OFil, LSize, sOut, sIn

Arg = WScript.Arguments(0)

LRet = MsgBox("Click yes to encode file or no to decode.", 36)
  If LRet = 6 Then
      IfEncode = True
  Else
      IfEncode = False
  End If

Set FSO = CreateObject("Scripting.FileSystemObject")
Set OFil = FSO.GetFile(Arg)
LSize = OFil.Size
Set OFil = Nothing
Set TS = FSO.OpenTextFile(Arg)
sIn = TS.Read(LSize)
Set TS = Nothing

t1 = timer
If ifencode = True Then
  sOut = Base64Encode(sIn)
  Set TS = FSO.CreateTextFile(Arg & "-en64", True)
         TS.Write sOut
         TS.Close
    Set TS = Nothing
Else
 sOut = Base64Decode(sIn)
   Set TS = FSO.CreateTextFile(Arg & "-de64", True)
         TS.Write sOut
         TS.Close
    Set TS = Nothing
End If
t2 = timer
Set FSO = Nothing
MsgBox CStr(t2 - t1)

Function Base64Encode(sText)
    Dim oXML, oNode
    Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
    Set oNode = oXML.CreateElement("base64")
    oNode.dataType = "bin.base64"
    oNode.nodeTypedValue = Stream_StringToBinary(sText)
    Base64Encode = oNode.text
    Set oNode = Nothing
    Set oXML = Nothing
End Function

Function Base64Decode(ByVal vCode)
    Dim oXML, oNode
    Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
    Set oNode = oXML.CreateElement("base64")
    oNode.dataType = "bin.base64"
    oNode.text = vCode
    Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
    Set oNode = Nothing
    Set oXML = Nothing
End Function

Private Function Stream_StringToBinary(Text)
  Const adTypeText = 2
  Const adTypeBinary = 1
  Dim BinaryStream 'As New Stream
  Set BinaryStream = CreateObject("ADODB.Stream")
  BinaryStream.Type = adTypeText
  BinaryStream.CharSet = "Windows-1252"
  BinaryStream.Open
  BinaryStream.WriteText Text
  BinaryStream.Position = 0
  BinaryStream.Type = adTypeBinary
  BinaryStream.Position = 0
  Stream_StringToBinary = BinaryStream.Read
  Set BinaryStream = Nothing
End Function

Private Function Stream_BinaryToString(Binary)
  Const adTypeText = 2
  Const adTypeBinary = 1
  Dim BinaryStream 'As New Stream
  Set BinaryStream = CreateObject("ADODB.Stream")
  BinaryStream.Type = adTypeBinary
  BinaryStream.Open
  BinaryStream.Write Binary
  BinaryStream.Position = 0
  BinaryStream.Type = adTypeText
  BinaryStream.CharSet = "Windows-1252"
  Stream_BinaryToString = BinaryStream.ReadText
  Set BinaryStream = Nothing
End Function 

Back to microsoft.public.scripting.vbscript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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