views:

12

answers:

0

I have a service writing remote files, but it requires a byte array as input. Rest of the interface provides only JavaScript unicode strings. No way to write them then.

I found something like this in MDC:

var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
                .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
var s = {};
var tt = 'test string';
var data = converter.convertToByteArray(tt, s);

According to what they say in MDC, this should do exactly what I need, but it fails with this: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIScriptableUnicodeConverter.convertToByteArray]

In docs there is the string must not be UTF-16, and I've read JS uses UTF-16 by default.

Any other ways to produce this damn byte array from string?