OS.File.Info

  • Revision slug: JavaScript_OS.File/OS.File.Info
  • Revision title: OS.File.Info
  • Revision id: 320965
  • Created:
  • Creator: Yoric
  • Is current revision? No
  • Comment

Revision Content

Instances of OS.File.Info represent file metadata, such as the size of the file, its last modification date, etc. Due to differences between operating systems, the information available depends on the platform.

Instances of OS.File.Info may be obtained by:

Using OS.File.Info

Example: Determining if a file is a regular file

The following snippet uses the main thread API to determine (asynchronously) whether some path is a regular file, or a directory, or a symbolic link:

let promise = OS.File.stat(somePath);
promise.then(
  function onSuccess(info) { // |info| is an instance of |OS.File.Info|
    if (info.isDir) {
      // |somePath| represents a directory
    } else if (info.isSymLink) {
      // |somePath| represents a symbolic link
    } else {
      // |somePath| represents a regular file
    }
  },
  function onFailure(reason) {
    if (reason instanceof OS.File.Error && reason.becauseNoSuchFile) {
      // |somePath| does not represent anything
    } else {
      // some other error
    }
  }
)

Example: Determining the owner of a file

let promise = OS.File.stat()
promise.then(
  function onSuccess(info) {
    if ("unixOwner" in info) {
       // info.unixOwner holds the owner of the file 
    } else {
       // Information is not available on this platform
    }
  }
);

Evolution of this example

Bug 802534 will introduce the ability to check whether field unixOwner appears in OS.File.Info.prototype, which will make it possible to write faster code.

Global object OS.File.Info

Methods

object toMsg(in OS.File.Info value)

OS.File.toMsg

Convert an instance of OS.File.Info to a form that can be serialized and transmitted between threads or processes.

object toMsg(
  in OS.File.Info value
)
Arguments
Returns

An object with the same fields as value but that may be serialized and transmitted between threads or processes.

value
An instance of OS.File.Info.

Instances of OS.File.Info

Cross-platform Attributes

isDir true if the file is a directory, false otherwise.
isSymLink true if the false is a symbolic link, false otherwise.
size The number of bytes in the file.
creationDate The Date at which the file was created.
lastAccessDate The Date at which the file was last accessed. Note that the definition of last access may depend on the underlying operating system and file system.
lastModificationDate The Date at which the file was last modified.

Platform-specific attributes (Unix)

unixOwner A number holding the identifier of the Unix owner of this file.
unixGroup A number holding the identifier of the Unix group of this file.
unixMode A number holding the Unix access rights to this file.

 

Revision Source

<p>Instances of OS.File.Info represent file metadata, such as the size of the file, its last modification date, etc. Due to differences between operating systems, the information available depends on the platform.</p>
<p>Instances of OS.File.Info may be obtained by:</p>
<ul>
  <li>calling global method <code>OS.File.stat()</code> either <a href="/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread#OS.File.stat" title="/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread">from the main thread</a> or <a href="/en-US/docs/JavaScript_OS.File/OS.File_for_workers#OS.File.stat" title="/en-US/docs/JavaScript_OS.File/OS.File_for_workers">from a worker thread</a>;</li>
  <li>calling instance method <code>stat()</code> of <code>OS.File</code> either <a href="/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread#OS.File.prototype.stat" title="/en-US/docs/JavaScript_OS.File/OS.File_for_the_main_thread#OS.File.prototype.stat">from the main thread</a> or <a href="/en-US/docs/JavaScript_OS.File/OS.File_for_workers#OS.File.prototype.stat" title="/en-US/docs/JavaScript_OS.File/OS.File_for_workers#OS.File.prototype.stat">from a worker thread</a>.</li>
</ul>
<h2 id="Using_OS.File.Info">Using OS.File.Info</h2>
<h3 id="Example.3A_Determining_if_a_file_is_a_regular_file">Example: Determining if a file is a regular file</h3>
<p>The following snippet uses the main thread API to determine (asynchronously) whether some path is a regular file, or a directory, or a symbolic link:</p>
<pre class="brush: js">
let promise = OS.File.stat(somePath);
promise.then(
  function onSuccess(info) { // |info| is an instance of |OS.File.Info|
    if (info.isDir) {
      // |somePath| represents a directory
    } else if (info.isSymLink) {
      // |somePath| represents a symbolic link
    } else {
      // |somePath| represents a regular file
    }
  },
  function onFailure(reason) {
    if (reason instanceof OS.File.Error &amp;&amp; reason.becauseNoSuchFile) {
      // |somePath| does not represent anything
    } else {
      // some other error
    }
  }
)
</pre>
<h3 id="Example.3A_Determining_the_owner_of_a_file">Example: Determining the owner of a file</h3>
<pre class="brush: js">
let promise = OS.File.stat()
promise.then(
  function onSuccess(info) {
    if ("unixOwner" in info) {
       // info.unixOwner holds the owner of the file 
    } else {
       // Information is not available on this platform
    }
  }
);

</pre>
<div class="note">
  <p><strong>Evolution of this example</strong><br />
    <br />
    <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=802534" title="https://bugzilla.mozilla.org/show_bug.cgi?id=802534">Bug 802534</a> will introduce the ability to check whether field <code>unixOwner</code> appears in <code>OS.File.Info.prototype</code>, which will make it possible to write faster code.</p>
</div>
<h2 id="Global_object_OS.File.Info">Global object OS.File.Info</h2>
<h4 id="Methods">Methods</h4>
<table>
  <tbody>
    <tr>
      <td>object <a href="#OS.File.toMsg" title="#OS.File.toMsg">toMsg</a>(in OS.File.Info value)</td>
    </tr>
  </tbody>
</table>
<h4 id="OS.File.toMsg">OS.File.toMsg<a name="OS.File.toMsg"></a></h4>
<p>Convert an instance of OS.File.Info to a form that can be serialized and transmitted between threads or processes.</p>
<pre class="brush: js">
object toMsg(
  in OS.File.Info value
)</pre>
<h5 id="Arguments">Arguments</h5>
<h5 id="Returns">Returns</h5>
<p>An object with the same fields as value but that may be serialized and transmitted between threads or processes.</p>
<dl>
  <dt>
    value</dt>
  <dd>
    An instance of OS.File.Info.</dd>
</dl>
<h2 id="Instances_of_OS.File.Info">Instances of OS.File.Info</h2>
<h4 id="Cross-platform_Attributes">Cross-platform Attributes</h4>
<table>
  <tbody>
    <tr>
      <td>isDir</td>
      <td>true if the file is a directory, false otherwise.</td>
    </tr>
    <tr>
      <td>isSymLink</td>
      <td>true if the false is a symbolic link, false otherwise.</td>
    </tr>
    <tr>
      <td>size</td>
      <td>The number of bytes in the file.</td>
    </tr>
    <tr>
      <td>creationDate</td>
      <td>The Date at which the file was created.</td>
    </tr>
    <tr>
      <td>lastAccessDate</td>
      <td>The Date at which the file was last accessed. Note that the definition of <em>last access</em> may depend on the underlying operating system and file system.</td>
    </tr>
    <tr>
      <td>lastModificationDate</td>
      <td>The Date at which the file was last modified.</td>
    </tr>
  </tbody>
</table>
<h4 id="Platform-specific_attributes_(Unix)">Platform-specific attributes (Unix)</h4>
<table>
  <tbody>
    <tr>
      <td>unixOwner</td>
      <td>A number holding the identifier of the Unix owner of this file.</td>
    </tr>
    <tr>
      <td>unixGroup</td>
      <td>A number holding the identifier of the Unix group of this file.</td>
    </tr>
    <tr>
      <td>unixMode</td>
      <td>A number holding the Unix access rights to this file.</td>
    </tr>
  </tbody>
</table>
<p>&nbsp;</p>
Revert to this revision