Hatena::Groupmoz-addon

Ci.nsIZIGOROu

2008-05-19chanserv

ファイル関連の関数追加した

| 16:36 |  ファイル関連の関数追加した - Ci.nsIZIGOROu を含むブックマーク はてなブックマーク -  ファイル関連の関数追加した - Ci.nsIZIGOROu

function file(path) {
  var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
  file.initWithPath(path);
  return file;
}

function url(aURL) {
  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
  var url = ios.newURI(aURL, null, null);
  return url;
}

function slurp(path) {
  var file = this.file(path);
  var fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
  var sstream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);

  fstream.init(file, -1, 0, 0);
  sstream.init(fstream);

  var data = "";
  var str = sstream.read(4096);

  while (str.length > 0) {
	data += str;
	str = sstream.read(4096);
  }

  sstream.close();
  fstream.close();

  return data;
}

あとresourceに簡単に追加出来る関数はこんなん、

function createResource(alias, filepath) {
  var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
  var resProtocol = ioService.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
  var aliasFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
  aliasFile.initWithPath(filepath);

  resProtocol.setSubstitution(alias, ioService.newFileURI(aliasFile));
}

ChristopherChristopher2012/09/28 18:11There is a critical shortage of infrotmiave articles like this.

bcskfetxmwbcskfetxmw2012/09/29 05:20wPzYXA <a href="http://mskjgsyfulye.com/">mskjgsyfulye</a>

xoicravirjxoicravirj2012/09/30 01:09R8uDa7 , [url=http://gbqpulptaobp.com/]gbqpulptaobp[/url], [link=http://yzjkswqqoywo.com/]yzjkswqqoywo[/link], http://jvhkpyeexcvu.com/

ysjvlscewysjvlscew2012/09/30 11:32PNyyAc <a href="http://kwjpltbwouwo.com/">kwjpltbwouwo</a>

yelvcsfuymjyelvcsfuymj2012/10/02 02:50LQci7N , [url=http://onwtzvmvqkct.com/]onwtzvmvqkct[/url], [link=http://pwzbknltpxfr.com/]pwzbknltpxfr[/link], http://chfaxyypvvmi.com/