Reputation:
Background:
I am using Clojure, on Java 7.0 on Ubuntu Linux 12.10, with an Ext4 file system.
Problem:
I have an arbitrary Clojure string. I would like to encode it into a valid filename.
Question:
What is the optimal way / what is a good builtin for doing this?
Note:
The encoded file name does not have to be human readable. I just need to be able to recover the original string from the filename.
EDIT:
Although if strings that are valid names gets mapped to something that is human readbale (and close to it's original value, that would be nice too.)
Thanks!
EDIT:
encode: takes arbitrary string as input; creates valid filename as output
decode: takes file name from encode, recovers original string
Upvotes: 1
Views: 282
Reputation: 180787
If it doesn't need to be human readable, just base64 encode it. That will remove any file name invalid characters from the string.
http://richhickey.github.com/clojure-contrib/base64-api.html
If they still don't have a decoder in native clojure, use a Java base64 decode function.
Upvotes: 1