<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shawn Wilsher &#187; NetUtil</title>
	<atom:link href="http://shawnwilsher.com/archives/tag/netutil/feed" rel="self" type="application/rss+xml" />
	<link>http://shawnwilsher.com</link>
	<description></description>
	<lastBuildDate>Sun, 04 Dec 2011 10:37:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>NetUtil.jsm Just Got More Useful</title>
		<link>http://shawnwilsher.com/archives/366</link>
		<comments>http://shawnwilsher.com/archives/366#comments</comments>
		<pubDate>Tue, 29 Dec 2009 19:21:56 +0000</pubDate>
		<dc:creator>Shawn Wilsher</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[NetUtil]]></category>

		<guid isPermaLink="false">http://shawnwilsher.com/?p=366</guid>
		<description><![CDATA[Recently, a few bugs have landed enabling a bunch of nice things for consumers of NetUtil.jsm: NetUtil.newURI can take a string (plus optional character set and base URI) or an nsIFile. A new method for creating channels has been created. NetUtil.newChannel can take an nsIURI, a string (plus optional character set and base URI), or [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=532143" title="NetUtil.newURI should take a string or nsIFile">a</a> <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=532146" title="NetUtil.jsm needs a helper for creating new channels">few</a> <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=532147" title="NetUtil.asyncFetch should take an nsIURI, string, nsIFile, or nsIChannel">bugs</a> have landed enabling a bunch of nice things for consumers of <tt>NetUtil.jsm</tt>:</p>
<ul>
<li><tt>NetUtil.newURI</tt> can take a string (plus optional character set and base URI) or an <tt>nsIFile</tt>.</li>
<li>A new method for creating channels has been created.  <tt>NetUtil.newChannel</tt> can take an <tt>nsIURI</tt>, a string (plus optional character set and base URI), or an <tt>nsIFile</tt>.</li>
<li><tt>NetUtil.asyncFetch</tt> can take an <tt>nsIChannel</tt>,  an <tt>nsIURI</tt>, a string (plus optional character set and base URI), or an <tt>nsIFile</tt>.</li>
</ul>
<p>This means, among other things, that it now requires less code to read a file asynchronously than it does synchronously.  The old way to do this asynchronously <a href="https://developer.mozilla.org/en/Code_snippets/File_I%2f%2fO#Asynchronously" title="Asynchronously Reading a File">can be seen here on MDC</a>.  This would give the consumer a byte array of the data in the file.  Compared to the synchronous case, which <a href="https://developer.mozilla.org/index.php?title=en/Code_snippets/File_I%2F%2FO#Simple" title="Synchronously Reading a File">can be seen here</a>.  Both are pretty verbose and clunky to use.  The new way looks like this:</p>
<pre><code>
NetUtil.asyncFetch(file, function(aInputStream, aResult) {
  if (!Components.isSuccessCode(aResult)) {
    // Handle Error
    return;
  }
  // Consume input stream
});
</code></pre>
<p>One function call, with a callback passed in.  There is a slight difference from the old asynchronous method, however.  <tt>NetUtil.asyncFetch</tt> gives the consumer an <tt>nsIInputStream</tt> instead of a byte array.  The input stream is a bit more useful than a raw byte array, although it can be painful to use in JavaScript at times (maybe we need an easy method to convert an input stream to a string?).  I look forward to patches using this method to read files instead of doing it synchronously.</p>
]]></content:encoded>
			<wfw:commentRss>http://shawnwilsher.com/archives/366/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>New API Added on NetUtil</title>
		<link>http://shawnwilsher.com/archives/310</link>
		<comments>http://shawnwilsher.com/archives/310#comments</comments>
		<pubDate>Thu, 03 Sep 2009 18:36:04 +0000</pubDate>
		<dc:creator>Shawn Wilsher</dc:creator>
				<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[NetUtil]]></category>

		<guid isPermaLink="false">http://shawnwilsher.com/?p=310</guid>
		<description><![CDATA[Did you know about the handy NetUtil object available when you import NetUtil.jsm? I bet you didn&#8217;t since it&#8217;s fairly new! There&#8217;s no MDC page yet, but the API is getting even better. Bug 508902 added a new method on NetUtil to create nsIURI objects. NetUtil will cache the IO Service so the calling site [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know about the handy <tt>NetUtil</tt> object available when you import <a href="http://mxr.mozilla.org/mozilla-central/source/netwerk/base/src/NetUtil.jsm"><tt>NetUtil.jsm</tt></a>?  I bet you didn&#8217;t since it&#8217;s fairly new!  There&#8217;s no MDC page yet, but the API is getting even better.  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=508902" title=" NetUtil.jsm should have a newURI method">Bug 508902</a> added a new method on <tt>NetUtil</tt> to create <tt>nsIURI</tt> objects.  <tt>NetUtil</tt> will cache the IO Service so the calling site doesn&#8217;t have to.  As more code starts to use this, fewer objects will have to cache the IO Service themselves.</p>
<p>The API mirrors <a href="https://developer.mozilla.org/en/nsIIOService#newURI.28.29"><tt>nsIOService</tt>&#8216;s <code>newURI</code></a> method with one minor improvement; the last two arguments are optional.  Most callers in JavaScript tend to pass null for those last two arguments anyway, but when using <tt>NetUtil.newURI</tt>, they just have to pass the spec which should be easier.</p>
<p>New JavaScript code that needs to create <tt>nsIURI</tt> objects should start using this method.</p>
]]></content:encoded>
			<wfw:commentRss>http://shawnwilsher.com/archives/310/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

