[Project_owners] nsISeekableStream

Gerald Vogt vogt at spamcop.net
Wed Oct 12 17:05:04 EDT 2005

Hi Stan,

Stan James wrote:
> I'm trying to to some seeking within files. I can open and write files 
> using some good examples (http://www.captain.at/programming/xul/), but I 
> can't figure out how to use nsISeekableStream methods (e.g. "seek()") on 
> a stream which I open with the nsIFileOutputStream method "init()"?

You have to check the stream if it is an instance of 
Components.interfaces.nsISeekableStream. If it is the stream objects 
automatically reveals the functions of the interface. You can download 
moji from moji.mozdev.org, extract the XPI and have a look into 
dictionary.js where I wrote an File object which supports seeking.

The short version to open and seek into my chrome files:

this.path = "chrome://moji/foobar...";
this.uri = 
this.uri.spec = aPath;
this.fios = 
this.chan = this.fios.newChannelFromURI(this.uri);
this.istream = this.chan.open();

if (this.istream instanceof Components.interfaces.nsISeekableStream) {
   this.istream.seek(NS_SEEK_SET, offset);


More information about the Project_owners mailing list