Background:
I am using Clojure, on Java 7.0 on Ubuntu Linux 12.10, with an Ext4 file system.
我正在使用Clojure,在Ubuntu Linux 12.10上的Java 7.0上,使用Ext4文件系统。
Problem:
I have an arbitrary Clojure string. I would like to encode it into a valid filename.
我有一个任意的Clojure字符串。我想将其编码为有效的文件名。
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.)
虽然如果有效名称的字符串被映射到人类readbale的东西(并且接近它的原始值,那也很好。)
Thanks!
EDIT:
encode: takes arbitrary string as input; creates valid filename as output
encode:将任意字符串作为输入;创建有效文件名作为输出
decode: takes file name from encode, recovers original string
decode:从编码中获取文件名,恢复原始字符串
1 个解决方案
#1
1
If it doesn't need to be human readable, just base64 encode it. That will remove any file name invalid characters from the string.
如果它不需要是人类可读的,只需对base64进行编码即可。这将从字符串中删除任何文件名无效字符。
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.
如果他们仍然没有本机clojure中的解码器,请使用Java base64解码功能。
#1
1
If it doesn't need to be human readable, just base64 encode it. That will remove any file name invalid characters from the string.
如果它不需要是人类可读的,只需对base64进行编码即可。这将从字符串中删除任何文件名无效字符。
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.
如果他们仍然没有本机clojure中的解码器,请使用Java base64解码功能。