[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 = 
Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);
this.uri.spec = aPath;
this.fios = 
Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
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);
}

Gerald


More information about the Project_owners mailing list