1

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?

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
Harry
  • 4,524
  • 4
  • 42
  • 81

1 Answers1

1

You must assing the charset! For example: converter.charset = 'UTF-8';

Yorick
  • 26
  • 1