realbasic-nug
[Top] [All Lists]

Re: Encodings and GetSaveInfo

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Encodings and GetSaveInfo
From: Joe Strout <joe at inspiringapps dot com>
Date: Wed, 30 Apr 2008 08:25:19 -0600
Authentication-results: mx.google.com; spf=pass (google.com: domain of realbasic-nug-bounces at lists dot realsoftware dot com designates 66.116.103.65 as permitted sender) smtp dot mail=realbasic-nug-bounces at lists dot realsoftware dot com
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <AB12BA23-ED6E-44A1-B1CC-F1C9C04FB9B3 at realsoftware dot com> <9123A4FF-560B-4B83-AB3C-49ABCF5AD684 at thezaz dot com> <10E2A746-5561-46A2-9A79-55D68277520F at great-white-software dot com> <AE48D939-7716-4A9A-BA87-7A0939BE6856 at thezaz dot com> <7B362B0B-F42E-4DCA-86D7-DFAC2AE374AE at great-white-software dot com> <C52A6682-1C8A-4F15-978B-B488497C85F1 at sentman dot com> <B8E23D21-3964-4EB0-9A41-E50C38F2EFBD at great-white-software dot com> <20080430051256 dot ELAV3194 dot aarprv06 dot charter dot net at CB56611-W dot chickensys dot com> <A10A86A0-B382-4603-8612-EED99F47DBD0 at great-white-software dot com> <175C567D-A57C-4D8D-AAF4-DE12FF946130 at declareSub dot com>
On Apr 30, 2008, at 7:38 AM, Charles Yeomans wrote:

>> DefineEncoding to nil perhaps ?
>
> This is a no-op, as I recall.

No, it works fine.  However, let's get back to the original question;  
Garth wrote:

> I am trying to save a Folderitem to a .plist. I use GetSaveInfo to
> get the string. Its encoding at that time is Nil.

This is correct.  It's binary data, not text.

> I store it in a .plist dictionary (I use that popular PLIST class
> that circulates).

This is a mistake.  The Plist class almost certainly expects text,  
not binary data.

> During the life of the session if I access the entry the encoding
> stays Nil and it works if I stuff it back to GetRelative.

Sure, because it's just handing you back the data you gave it.  It's  
not until it's written to a (text) file that it must be treated as text.

> However, when I exit the app, the PLIST class writes it permanently
> back the file. So when I access the string again when I start up the
> app again, often (but not always) the string retrieved has a UTF or
> some encoding to it

I'd expect it to be always.  It's reading a text file, so it has to  
assume some encoding for the text.

> and thus that corrupts the string and then I can't get the  
> FodlerItem again.

No, having an encoding doesn't corrupt the string; it was corrupted  
by trying to treat it as text.  It may happen to contain line breaks  
and other things that make a mess of the plist file.   
FolderItem.GetRelative expects binary data, and ignores any encoding  
set on the string; it would work fine if the bytes were right -- but  
the bytes by this point are wrong.

> So, how do you remove an encoding from a string? Or should that be  
> my question?


No, it should not.  Removing the encoding from the incorrect bytes  
won't make them right.

The right solution, as Norman suggested, is to EncodeBase64 your save  
info (converting it from binary to text data) before stuffing it into  
your plist.  And then when you get it out, DecodeBase64 to get the  
binary data back.

Best,
- Joe


--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>