<h4>@options {Object} Options for this instance</h4>
<p>Constructor function for the File nconf store, a simple abstraction
around the Memory store that can persist configuration to disk.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="kd">var</span><spanclass="nx">File</span><spanclass="o">=</span><spanclass="nx">exports</span><spanclass="p">.</span><spanclass="nx">File</span><spanclass="o">=</span><spanclass="kd">function</span><spanclass="p">(</span><spanclass="nx">options</span><spanclass="p">)</span><spanclass="p">{</span>
<spanclass="p">};</span></pre></div></td></tr><trid="section-3"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-3">¶</a></div><p>Inherit from the Memory store</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">util</span><spanclass="p">.</span><spanclass="nx">inherits</span><spanclass="p">(</span><spanclass="nx">File</span><spanclass="p">,</span><spanclass="nx">Memory</span><spanclass="p">);</span></pre></div></td></tr><trid="section-4"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-4">¶</a></div><h3>function save (value, callback)</h3>
<h4>@value {Object} <em>Ignored</em> Left here for consistency</h4>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Saves the current configuration object to disk at <code>this.file</code>
using the format specified by <code>this.format</code>.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">File</span><spanclass="p">.</span><spanclass="nx">prototype</span><spanclass="p">.</span><spanclass="nx">save</span><spanclass="o">=</span><spanclass="kd">function</span><spanclass="p">(</span><spanclass="nx">value</span><spanclass="p">,</span><spanclass="nx">callback</span><spanclass="p">)</span><spanclass="p">{</span>
using the format specified by <code>this.format</code> synchronously.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">File</span><spanclass="p">.</span><spanclass="nx">prototype</span><spanclass="p">.</span><spanclass="nx">saveSync</span><spanclass="o">=</span><spanclass="kd">function</span><spanclass="p">(</span><spanclass="nx">value</span><spanclass="p">)</span><spanclass="p">{</span>
<h4>@callback {function} Continuation to respond to when complete.</h4>
<p>Responds with an Object representing all keys associated in this instance.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">File</span><spanclass="p">.</span><spanclass="nx">prototype</span><spanclass="p">.</span><spanclass="nx">load</span><spanclass="o">=</span><spanclass="kd">function</span><spanclass="p">(</span><spanclass="nx">callback</span><spanclass="p">)</span><spanclass="p">{</span>
<spanclass="k">if</span><spanclass="p">(</span><spanclass="o">!</span><spanclass="nx">exists</span><spanclass="p">)</span><spanclass="p">{</span></pre></div></td></tr><trid="section-7"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-7">¶</a></div><p>If the path we are attempting to load doesn't exist, create it</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">self</span><spanclass="p">.</span><spanclass="nx">save</span><spanclass="p">({},</span><spanclass="kd">function</span><spanclass="p">(</span><spanclass="nx">err</span><spanclass="p">)</span><spanclass="p">{</span>
<spanclass="k">else</span><spanclass="p">{</span></pre></div></td></tr><trid="section-8"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-8">¶</a></div><p>Else, the path exists, read it from disk</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">fs</span><spanclass="p">.</span><spanclass="nx">readFile</span><spanclass="p">(</span><spanclass="nx">self</span><spanclass="p">.</span><spanclass="nx">file</span><spanclass="p">,</span><spanclass="kd">function</span><spanclass="p">(</span><spanclass="nx">err</span><spanclass="p">,</span><spanclass="nx">data</span><spanclass="p">)</span><spanclass="p">{</span>
<p>Attempts to load the data stored in <code>this.file</code> synchronously and responds appropriately.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">File</span><spanclass="p">.</span><spanclass="nx">prototype</span><spanclass="p">.</span><spanclass="nx">loadSync</span><spanclass="o">=</span><spanclass="kd">function</span><spanclass="p">()</span><spanclass="p">{</span>
<spanclass="k">if</span><spanclass="p">(</span><spanclass="o">!</span><spanclass="nx">path</span><spanclass="p">.</span><spanclass="nx">existsSync</span><spanclass="p">(</span><spanclass="nx">self</span><spanclass="p">.</span><spanclass="nx">file</span><spanclass="p">))</span><spanclass="p">{</span></pre></div></td></tr><trid="section-10"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-10">¶</a></div><p>If the path we are attempting to load doesn't exist, create it</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="nx">self</span><spanclass="p">.</span><spanclass="nx">saveSync</span><spanclass="p">({});</span>
<spanclass="k">else</span><spanclass="p">{</span></pre></div></td></tr><trid="section-11"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-11">¶</a></div><p>Else, the path exists, read it from disk</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="k">try</span><spanclass="p">{</span>
<spanclass="k">if</span><spanclass="p">(</span><spanclass="k">this</span><spanclass="p">.</span><spanclass="nx">file</span><spanclass="p">[</span><spanclass="mi">0</span><spanclass="p">]</span><spanclass="o">===</span><spanclass="s1">'/'</span><spanclass="p">)</span><spanclass="p">{</span></pre></div></td></tr><trid="section-13"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-13">¶</a></div><p>If filename for this instance is a fully qualified path
(i.e. it starts with a <code>'/'</code>) then check if it exists</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="k">try</span><spanclass="p">{</span>
<spanclass="k">if</span><spanclass="p">(</span><spanclass="nx">looking</span><spanclass="o">&&</span><spanclass="nx">base</span><spanclass="p">)</span><spanclass="p">{</span></pre></div></td></tr><trid="section-15"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-15">¶</a></div><p>Attempt to stat the realpath located at <code>base</code>
if the directory does not exist then return false.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="k">try</span><spanclass="p">{</span>
<spanclass="k">while</span><spanclass="p">(</span><spanclass="nx">looking</span><spanclass="p">)</span><spanclass="p">{</span></pre></div></td></tr><trid="section-16"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-16">¶</a></div><p>Iteratively look up the directory structure from <code>base</code></p></td><tdclass="code"><divclass="highlight"><pre><spanclass="k">try</span><spanclass="p">{</span>
<spanclass="k">if</span><spanclass="p">(</span><spanclass="nx">previous</span><spanclass="o">===</span><spanclass="nx">base</span><spanclass="p">)</span><spanclass="p">{</span></pre></div></td></tr><trid="section-17"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-17">¶</a></div><p>If we've reached the top of the directory structure then simply use
the default file path.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="k">try</span><spanclass="p">{</span>
<spanclass="p">}</span></pre></div></td></tr><trid="section-19"><tdclass="docs"><divclass="pilwrap"><aclass="pilcrow"href="#section-19">¶</a></div><p>Set the file for this instance to the fullpath
that we have found during the search. In the event that
the search was unsuccessful use the original value for <code>this.file</code>.</p></td><tdclass="code"><divclass="highlight"><pre><spanclass="k">this</span><spanclass="p">.</span><spanclass="nx">file</span><spanclass="o">=</span><spanclass="nx">fullpath</span><spanclass="o">||</span><spanclass="k">this</span><spanclass="p">.</span><spanclass="nx">file</span><spanclass="p">;</span>