Converting from unicode to ASCII

Bob Sneidar bobsneidar at iotecdigital.com
Wed Sep 23 11:09:04 EDT 2020


Duh. That was a stupid question. How do you get back to the filename?

Bob S


On Sep 23, 2020, at 8:08 AM, Bob Sneidar <bobsneidar at iotecdigital.com<mailto:bobsneidar at iotecdigital.com>> wrote:

Will binaryEncode get you back to the filename?

Bob S


On Sep 23, 2020, at 8:03 AM, Richard Gaskin via use-livecode <use-livecode at lists.runrev.com<mailto:use-livecode at lists.runrev.com>> wrote:

J. Landman Gay write:

> I'm looking for a way to create non-unicode file names
> based on the string that comes out of the database.

Ah, public clouds...

Amazon's S3 docs say just encoding in UTF-8 should suffice, but then they also list a lot of characters they consider "special", but common usage considers them not so special at all, so conflicts like this are apparently abundant.

One workaround for their storage name limitations I've seen used elsewhere is hash-based names, giving you a string that is plain ASCII, of a fixed and usable length, and is derived from the file name so systems don't need to maintain a lookup table to find the file based on a given string.

This will give you a 40-char string in plain ol' ASCII unique to the input:

   function CleanHash s
      get binaryDecode("h*", sha1Digest(s), tHash)
      return tHash
   end CleanHash

e.g.:

   get CleanHash("MyFile.txt")

...returns:

   d9275b8f757ce47c240d276c1e1192dae8585eba





More information about the use-livecode mailing list