How to convert a file with extended attributes to AppleDouble format?

How can I convert a file, which has extended attributes, to AppleDouble format? I know how to convert from AppleDouble format using the Terminal utility dot_clean, but what utility can be used to convert to AppleDouble format?


I haven’t found a utility that’s specifically intended to convert to AppleDouble format, but I realized ditto and unzip can be (ab)used to do this: ditto will convert to AppleDouble format when adding a file to a zip archive. Extracting the archive using ditto converts it back, but this is not the case when using the regular unzip command which retains the two files in AppleDouble format. Thus, one can do:

$ ditto -c -k file.txt archive.zip; unzip -o archive.zip
Archive:  archive.zip
  inflating: file.txt              
  inflating: ._file.txt

There must be a better way to do this, but I haven’t come across it yet.