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@lists.runrev.com<mailto:use-livecode@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

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to