[Gambas-user] Base 64 question
richard terry
rterry at ...1946...
Fri Apr 29 00:31:39 CEST 2011
On Friday 29 April 2011 00:57:17 Caveat wrote:
> xml.Decode...pfft! Funny, I never would have thought to look in gb.xml
> for a base64 decoder!
>
> Anyhoo, did you compare xml.Decode and the routine below with the decode
> function I wrote in the example project I sent earlier... or are you
> *still* waiting for my decode function to return a result? lol
Didn't yet test it, must admit I'd missed it in the post - pressure of work
and quick scrolling, I'll take a look
richard
>
> I'm wondering if the Wait is doing much useful in the subroutine below
> (in theory it should be allowing processing of all pending events, but
> no user interaction). Perhaps you could remove it and see what
> happens...
>
> Regards,
> Caveat
>
> On Thu, 2011-04-28 at 22:09 +1000, richard terry wrote:
> > On Thursday 28 April 2011 21:50:55 richard terry wrote:
> >
> > I've tried them both the xml reader and the subroutine below, on a
> > real-life file, a hl7 file containg a pdf of a vascular result
> >
> > this code written by
> > Christer Nygren <petterfilip at ...626...> and some others,
> >
> > on my machine seems considerably faster than the xml.decode function
> >
> > Public Sub FromB64(B64Str As String) As String
> > Dim Position As Long
> > Dim dt As Byte
> > Dim B64Decoded, u, c As String
> > Dim Tkn, p As Integer
> >
> > Position = 1
> > Tkn = 0
> > Do Until Position > Len(B64Str)
> > Wait
> > c = Mid(B64Str, Position, 1)
> > p = InStr(B64Const, c)
> > If p > 1 Then
> > p = p - 2
> > Inc Tkn
> > Select Case Tkn
> > Case 1
> > dt = (p * &h4)
> > Case 2
> > B64Decoded = B64Decoded & Chr(dt + ((p And &H30&) / &H10&))
> > dt = (p And &HF&) * &H10&
> > Case 3
> > B64Decoded = B64Decoded & Chr(dt + ((p And &H3C&) / 4))
> > dt = (p And &H3&) * &H40&
> > Case 4
> > B64Decoded = B64Decoded & Chr(dt + p)
> > End Select
> > If Tkn = 4 Then Tkn = 0
> > Else ' Ej skrivbart tecken
> > If p = 1 Then
> > Position = Len(B64Str) + 1
> > End If
> > Endif
> > Inc Position
> > Loop
> > Select Case Tkn
> > Case 1
> > B64Decoded = B64Decoded & Chr(dt)
> > End Select
> > Return B64Decoded
> > End
> >
> > ??coments from those who know?
> >
> > richard
> >
> > > On Thursday 28 April 2011 21:38:52 Fabien Bodard wrote:
> > > > Print XmlReader.Decode("strvalue", "Base64")
> > >
> > > Funny that, I based my head against a wall trying exactly that syntax,
> > > I eventually found some old gambas code on the web that worked.
> > >
> > > But... just typed it in again, and it works. Dunno......... maybe I
> > > didn't capitalise it or something.
> > >
> > > Anway, thanks.
> > >
> > > Like everything else in gambas, blindingly simple if you know.
> > >
> > >
> > > Richard
> > >
> > > > 2011/4/28 richard terry <rterry at ...1946...>:
> > > > > On Thursday 28 April 2011 20:16:31 Fabien Bodard wrote:
> > > > > I tried this:
> > > > > XmlReader.Decode(data, "?????"
> > > > >
> > > > > what goes in the encoding type "?????"
> > > > >
> > > > > I looked on the website to no avail
> > > > > I tried strings like "Base64", "base64" etc
> > > > >
> > > > > couldn't figure it out.
> > > > >
> > > > > any hlep appreciated.
> > > > >
> > > > > Richard
> > > > >
> > > > >> gb.xml !
> > > > >>
> > > > >> 2011/4/28 Caveat <Gambas at ...1950...>:
> > > > >> > Hi Richard,
> > > > >> >
> > > > >> > I don't know of any base64 decode function in Gambas, but then I
> > > > >> > didn't look that hard ;-)
> > > > >> >
> > > > >> > There are various different flavours of base64, so be sure you
> > > > >> > know which variant you're dealing with.
> > > > >> >
> > > > >> > I enclose with this mail a source archive of a little project
> > > > >> > I've put together (sorry, it's Gambas2, hope that's OK) that
> > > > >> > demonstrates decoding (and encoding) of base64 data. I found
> > > > >> > the information on how to put together the encode and decode
> > > > >> > algorithms here: http://en.wikipedia.org/wiki/Base64
> > > > >> >
> > > > >> > There's also a reference to base64 in Gambas here:
> > > > >> > http://www.gambasforum.com/index.php?topic=330.0
> > > > >> > The algorithms given in those code snippets could well be far
> > > > >> > more efficient than mine.
> > > > >> >
> > > > >> > My Base64 Project
> > > > >> > -----------------
> > > > >> > First thing to try is just hit the Encode button, it should
> > > > >> > convert the text in the top textarea into base64 and place the
> > > > >> > result in the lower textarea. Generally, if the In textbox is
> > > > >> > blank, the input for Encode or Decode will be the upper
> > > > >> > textarea, and if the Out textbox is blank, the output of the
> > > > >> > Encode or Decode will be shown in the lower textarea. To encode
> > > > >> > binary data, you'll need to use a file as input, so use the In
> > > > >> > textbox to specify the file name. To decode base64 that
> > > > >> > represents binary data, you'll need to use a file as output, so
> > > > >> > use the Out textbox to specify the output file name.
> > > > >> >
> > > > >> > You can try out binary to base64 using fluffy.jpg (shipped with
> > > > >> > the project) as your In file.
> > > > >> >
> > > > >> > To test round-trip (so start with a binary, encode it to base64,
> > > > >> > then decode the base64 data to make an identical binary)...
> > > > >> > enter fluffy.jpg in the In textbox, blank the Out textbox, hit
> > > > >> > Encode. In the lower textarea Select All, Copy... then in the
> > > > >> > upper textarea Paste. Now clear the In textbox and enter
> > > > >> > coffee.jpg in the Out textbox. Hit Decode. You *should* find a
> > > > >> > new file in your Base64 project directory called coffee.jpg, and
> > > > >> > it *should* be identical to the fluffy.jpg shipped with the
> > > > >> > project.
> > > > >> >
> > > > >> > I'm not convinced that my completely untuned, horribly
> > > > >> > inefficient algorithms in Gambas will be the best way to go if
> > > > >> > speed is of the essence or if the pdf files are gonna be more
> > > > >> > than a few 100 kbs... you might find it quicker/more robust to
> > > > >> > call out to a built-in function in java/python/some other
> > > > >> > program...
> > > > >> >
> > > > >> > Anyways, all the (commented) source is there for you to
> > > > >> > see/fiddle with...so have fun, but if you have any questions,
> > > > >> > just give me a shout.
> > > > >> >
> > > > >> > Regards,
> > > > >> > Caveat
> > > > >> >
> > > > >> > On Thu, 2011-04-28 at 07:38 +1000, Ian Haywood wrote:
> > > > >> >> No, HL7 parsing is fine, let me restate the question: does
> > > > >> >> gambas have an inbuilt function to
> > > > >> >> decode base 64 data?
> > > > >> >>
> > > > >> >> Ian
> > > > >> >>
> > > > >> >> On Thu, Apr 28, 2011 at 3:48 AM, nando
> > > > >> >> <nando_f at ...951...>
> > >
> > > wrote:
> > > > >> >> > Health Level 7 file format
> > > > >> >> > To start visit:
> > > > >> >> > http://en.wikipedia.org/wiki/Health_Level_7
> > > > >> >> >
> > > > >> >> >
> > > > >> >> > ---------- Original Message -----------
> > > > >> >> > From: richard terry <rterry at ...1946...>
> > > > >> >> > To: mailing list for gambas users
> > > > >> >> > <gambas-user at lists.sourceforge.net> Sent: Wed, 27 Apr 2011
> > > > >> >> > 18:13:57 +1000
> > > > >> >> > Subject: [Gambas-user] Base 64 question
> > > > >> >> >
> > > > >> >> >> Hi list,
> > > > >> >> >>
> > > > >> >> >> I've a HL7 file apparently with embedded base64 data (as a
> > > > >> >> >> pdf) I wondered if there iwas any way to de-encode the data,
> > > > >> >> >> if that is the right syntax.
> > > > >> >> >>
> > > > >> >> >> Regards
> > > > >> >> >>
> > > > >> >> >> Richard
> > > > >> >> >>
> > > > >> >> >> ------------------------------------------------------------
> > > > >> >> >>---- -- --- --------- WhatsUp Gold - Download Free Network
> > > > >> >> >> Management Software The most intuitive, comprehensive, and
> > > > >> >> >> cost-effective network management toolset available today.
> > > > >> >> >> Delivers lowest initial acquisition cost and overall TCO of
> > > > >> >> >> any competing solution. http://p.sf.net/sfu/whatsupgold-sd
> > > > >> >> >> _______________________________________________
> > > > >> >> >> Gambas-user mailing list
> > > > >> >> >> Gambas-user at lists.sourceforge.net
> > > > >> >> >> https://lists.sourceforge.net/lists/listinfo/gambas-user
> > > > >> >> >
> > > > >> >> > ------- End of Original Message -------
> > > > >> >> >
> > > > >> >> >
> > > > >> >> > -------------------------------------------------------------
> > > > >> >> >---- -- --- -------- WhatsUp Gold - Download Free Network
> > > > >> >> > Management Software The most intuitive, comprehensive, and
> > > > >> >> > cost-effective network management toolset available today.
> > > > >> >> > Delivers lowest initial acquisition cost and overall TCO of
> > > > >> >> > any competing solution. http://p.sf.net/sfu/whatsupgold-sd
> > > > >> >> > _______________________________________________
> > > > >> >> > Gambas-user mailing list
> > > > >> >> > Gambas-user at lists.sourceforge.net
> > > > >> >> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > > > >> >>
> > > > >> >> ---------------------------------------------------------------
> > > > >> >>---- -- --- ------ WhatsUp Gold - Download Free Network
> > > > >> >> Management Software The most intuitive, comprehensive, and
> > > > >> >> cost-effective network management toolset available today.
> > > > >> >> Delivers lowest initial acquisition cost and overall TCO of any
> > > > >> >> competing solution. http://p.sf.net/sfu/whatsupgold-sd
> > > > >> >> _______________________________________________
> > > > >> >> Gambas-user mailing list
> > > > >> >> Gambas-user at lists.sourceforge.net
> > > > >> >> https://lists.sourceforge.net/lists/listinfo/gambas-user
> > > > >> >
> > > > >> > ----------------------------------------------------------------
> > > > >> >---- -- --- ----- WhatsUp Gold - Download Free Network Management
> > > > >> > Software The most intuitive, comprehensive, and cost-effective
> > > > >> > network management toolset available today. Delivers lowest
> > > > >> > initial acquisition cost and overall TCO of any competing
> > > > >> > solution. http://p.sf.net/sfu/whatsupgold-sd
> > > > >> > _______________________________________________
> > > > >> > Gambas-user mailing list
> > > > >> > Gambas-user at lists.sourceforge.net
> > > > >> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > > > >
> > > > > -------------------------------------------------------------------
> > > > >---- -- ----- WhatsUp Gold - Download Free Network Management
> > > > > Software The most intuitive, comprehensive, and cost-effective
> > > > > network management toolset available today. Delivers lowest
> > > > > initial acquisition cost and overall TCO of any competing solution.
> > > > > http://p.sf.net/sfu/whatsupgold-sd
> > > > > _______________________________________________
> > > > > Gambas-user mailing list
> > > > > Gambas-user at lists.sourceforge.net
> > > > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > >
> > > -----------------------------------------------------------------------
> > >---- --- WhatsUp Gold - Download Free Network Management Software
> > > The most intuitive, comprehensive, and cost-effective network
> > > management toolset available today. Delivers lowest initial
> > > acquisition cost and overall TCO of any competing solution.
> > > http://p.sf.net/sfu/whatsupgold-sd
> > > _______________________________________________
> > > Gambas-user mailing list
> > > Gambas-user at lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> > -------------------------------------------------------------------------
> >----- WhatsUp Gold - Download Free Network Management Software
> > The most intuitive, comprehensive, and cost-effective network
> > management toolset available today. Delivers lowest initial
> > acquisition cost and overall TCO of any competing solution.
> > http://p.sf.net/sfu/whatsupgold-sd
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
>
> ---------------------------------------------------------------------------
> --- WhatsUp Gold - Download Free Network Management Software
> The most intuitive, comprehensive, and cost-effective network
> management toolset available today. Delivers lowest initial
> acquisition cost and overall TCO of any competing solution.
> http://p.sf.net/sfu/whatsupgold-sd
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
More information about the User
mailing list