Output binary data in base64 in YAML

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


I am writing an application that wishes to store persistent data in
plain text file.
I found that YAML may be a good utility to satisfy this need.
The data to be stored include jpeg image data and utf-8 asian text.
The utf-8 asian text is dumped by YAML in utf-8.
This is OK.
But the jpeg image data is dumped without any escape for byte values
over 0x80.
This is not satisfactory because I wish the user can use any plain text
editor to view/diff/edit the data file.

I did a simple test as below,
perl -e "use YAML;$a={'b'=>pack('H*', '00416181A1C1E1F1')};print

I redirected the output to a file and use emacs hexl-mode to view,
It displayed as,

00000000: 2d2d 2d20 2359 414d 4c3a 312e 300d 0a62  --- #YAML:1.0..b
00000010: 3a20 225c 7a41 6181 a1c1 e1f1 220d 0a    : "\zAa....."..

Apparently, only \x00 is escaped as \z. Other values are dumped intact.

The environment I use is,
ActivePerl Build 810 (perl 5.8.4)
YAML 0.35

I wish I can dump the binary data in base64.
How can I achieve this?
Thans in advance.

Site Timeline