Subj : Nulls in strings passed back from xpconnect To : mozilla-jseng@mozilla.org From : thomas@thurman.org.uk (Thomas Thurman) Date : Mon Jan 20 2003 03:48 pm This is rather a general question, but after quite a bit of searching I haven't found an answer to it: I'm using xpconnect to read in a file which will probably contain nulls. The read() method of nsIScriptableInputStream seems to be what I want (or am I wrong?), but when the string gets returned it's cut off at the first null. Here's an example session from xpcshell to show what I mean. "troll.z5" is a 64000-byte file; character 1 is a null, but characters 0 and 5 are not. js> a=new Components.Constructor( "@mozilla.org/network/local-file-channel;1", "nsIFileChannel")() [xpconnect wrapped nsIFileChannel] js> z=new Components.Constructor( "@mozilla.org/file/local;1", "nsILocalFile", "initWithPath")( "troll.z5") [xpconnect wrapped nsILocalFile] js> b=new Components.Constructor( "@mozilla.org/scriptableinputstream;1", "nsIScriptableInputStream")() [xpconnect wrapped nsIScriptableInputStream] js> a.init(z, 1, 0) js> b.init(a.open()) js> r=b.read(64000) js> r.length 1 js> r.charCodeAt(5) NaN It's possible to work around the problem by reading the file in a byte at a time, but that's enormously slow. Is there any way of: * allowing the null to be passed back in the string? (Spidermonkey doesn't seem to have a problem with nulls in strings in general) * using something not a string to receive the data (say, an array?) * using an XPCOM component to represent the string so that the conversion never happens? T .