Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Oct 18, 2018 2:45 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: where can I get a plugin for "Base64encode"
PostPosted: Tue Jul 22, 2008 8:44 pm 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
Strange.

I have this:

dim membb as new MemoryBlock(0)
dim bb as new BinaryStream(membb)
dim s,temp as string

headers = false
contents = inputstream.Read(inputstream.Length)
dim df as new ZStreamWriter(bb,headers)
df.Write(contents)
df.Close()

temp = bb.Read(bb.Length)

s = Base64Encode(temp)

return s


The above defines a binarystream that contains a memoryblock, where the gzipped contents of a binary file are placed.

When I get to "temp = bb.Read.." I have 17313 bytes of compressd data in it. But temp doesn't pick them, nor does s ever returns anything other than a big, fat, blank.

Am I missing something here?

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


Top
 Profile  
Reply with quote  
 Post subject: Re: where can I get a plugin for "Base64encode"
PostPosted: Tue Jul 22, 2008 11:08 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
what is bb's length ?

you might need to reset bb.position to 0 before you read
try
bb.position = 0
temp = bb.Read(bb.Length)

also use EncodeBase64 if you dont want to have to rely on a plugin

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: where can I get a plugin for "Base64encode"
PostPosted: Wed Jul 23, 2008 12:59 am 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
That code looks somewhat dangerous to me. You've got a zero byte memoryblock that you're stuffing 1700 bytes into? Does that really work? Is there some magic in the binarystream that automatically allocates more memory for you as needed?

Tim


Top
 Profile  
Reply with quote  
 Post subject: Re: where can I get a plugin for "Base64encode"
PostPosted: Wed Jul 23, 2008 2:25 am 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
npalardy wrote:
what is bb's length ?

you might need to reset bb.position to 0 before you read
try
bb.position = 0
temp = bb.Read(bb.Length)

also use EncodeBase64 if you dont want to have to rely on a plugin


Good point about the native encodebase64. I had actually planned to do it and forgot about it.

bb's length is, obviously, bb.length :) . I hadn't thought about resetting the position either (you can tell I'm not used to memoryblocks and binarystreams, probably).

timhare wrote:
That code looks somewhat dangerous to me. You've got a zero byte memoryblock that you're stuffing 1700 bytes into? Does that really work? Is there some magic in the binarystream that automatically allocates more memory for you as needed?


Well, I did ask. I openly admit not having worked with memoryblocks or binarystreams before (everything I've had to use has been XMLRPC sending HTTP XML back and forth, dealing with the user interface). The only time I needed working with memoryblocks I requested help here and that was something pretty different to this.

I don't mind being corrected. I wouldn't be surprised, considering I half-pasted, half wrote what's on this post at almost 3 in the morning.

That having been said, I did base the code in an example in the LR:

Quote:
MemoryBlocks supports creating a zero-length MemoryBlock.
...
This example backs a BinarySream with a MemoryBlock that is declared 0-sized.

See Also NewMemoryBlock function.
MenuItem Class
An individual menu item.
Super Class Object
Properties
Dim mb as New MemoryBlock(0)
Dim bs as New BinaryStream(mb)
bs.WriteLong(4)
bs.WriteDouble(3.14)
bs.Close
MsgBox Str(mb.Long (0))


I could very well be wrong, but then I'm baffled at how it changes from the example.

I have long ago decided half of what RB does is "magic" anyway, so I wouldn't have a problem with considering this as such.

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


Top
 Profile  
Reply with quote  
 Post subject: Re: where can I get a plugin for "Base64encode"
PostPosted: Wed Jul 23, 2008 10:17 am 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
timhare wrote:
That code looks somewhat dangerous to me. You've got a zero byte memoryblock that you're stuffing 1700 bytes into? Does that really work? Is there some magic in the binarystream that automatically allocates more memory for you as needed?


You betcha :)
You can back a binary stream in several ways and a memoryblock is one
Very handy for all kinds of in memory conversions

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: where can I get a plugin for "Base64encode"
PostPosted: Wed Jul 23, 2008 10:19 am 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
eduo wrote:
That having been said, I did base the code in an example in the LR:

Quote:
MemoryBlocks supports creating a zero-length MemoryBlock.
...
This example backs a BinarySream with a MemoryBlock that is declared 0-sized.

See Also NewMemoryBlock function.
MenuItem Class
An individual menu item.
Super Class Object
Properties
Dim mb as New MemoryBlock(0)
Dim bs as New BinaryStream(mb)
bs.WriteLong(4)
bs.WriteDouble(3.14)
bs.Close
MsgBox Str(mb.Long (0))


I could very well be wrong, but then I'm baffled at how it changes from the example.


They read the memory block
you're trying to read the binary stream backed by the memory block

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: where can I get a plugin for "Base64encode"
PostPosted: Wed Jul 23, 2008 12:21 pm 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
npalardy wrote:
timhare wrote:
That code looks somewhat dangerous to me. You've got a zero byte memoryblock that you're stuffing 1700 bytes into? Does that really work? Is there some magic in the binarystream that automatically allocates more memory for you as needed?


You betcha :)
You can back a binary stream in several ways and a memoryblock is one
Very handy for all kinds of in memory conversions


Which is what I had in mind when I put it. I've seen the other message and I'll see about it.

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


Top
 Profile  
Reply with quote  
 Post subject: Re: where can I get a plugin for "Base64encode"
PostPosted: Wed Jul 23, 2008 6:03 pm 
Offline

Joined: Sun Jun 24, 2007 12:24 pm
Posts: 441
Location: Madrid
npalardy wrote:
what is bb's length ?

you might need to reset bb.position to 0 before you read
try
bb.position = 0
temp = bb.Read(bb.Length)

also use EncodeBase64 if you dont want to have to rely on a plugin


Aah. I love me some voodoo magiq going on behind the scenes.

The position did it, of course. Thanks a lot.

And of course I meant to use EncodeBase64, that was the point of all this to begin with. The MBS function is actually simpler but I don't want to rely on it unless really needed.

_________________
----
http://eduo.info/
http://gallery.eduo.info/
http://twitter.com/eduo/


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group