qz-tray
Version:
Connects a web client to the QZ Tray software. Enables printing and device communication from javascript.
2,578 lines (804 loc) • 38 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Namespace: file</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Namespace: file</h1>
<section>
<header>
<h2>
<span class="ancestors"><a href="qz.html">qz</a>.</span>file</h2>
</header>
<article>
<div class="container-overview">
<div class="description">Calls related to interactions with the filesystem</div>
<dl class="details">
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>2.1</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2525">line 2525</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".list"><span class="type-signature">(static) </span>list<span class="signature">(path, params<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<(Array.<String>|Error)>}</span></h4>
<div class="description">
List of files available at the given directory.<br/>
Due to security reasons, paths are limited to the qz data directory unless overridden via properties file.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>path</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">Relative or absolute directory path. Must reside in qz data directory or a white-listed location.</td>
</tr>
<tr>
<td class="name"><code>params</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Object containing file access parameters
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sandbox</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is only available to the certificate's connection, otherwise all connections</td>
</tr>
<tr>
<td class="name"><code>shared</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is accessible to all users on the system, otherwise just the current user</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2543">line 2543</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Array of files at the given path
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(Array.<String>|Error)></span>
</dd>
</dl>
<h4 class="name" id=".read"><span class="type-signature">(static) </span>read<span class="signature">(path, params<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<(String|Error)>}</span></h4>
<div class="description">
Reads contents of file at the given path.<br/>
Due to security reasons, paths are limited to the qz data directory unless overridden via properties file.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>path</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">Relative or absolute file path. Must reside in qz data directory or a white-listed location.</td>
</tr>
<tr>
<td class="name"><code>params</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Object containing file access parameters
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sandbox</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is only available to the certificate's connection, otherwise all connections</td>
</tr>
<tr>
<td class="name"><code>shared</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is accessible to all users on the system, otherwise just the current user</td>
</tr>
<tr>
<td class="name"><code>flavor</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
'plain'
</td>
<td class="description last">Flavor of data format used, valid flavors are <code>[base64 | hex | plain]</code>.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2561">line 2561</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
String containing the file contents
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(String|Error)></span>
</dd>
</dl>
<h4 class="name" id=".remove"><span class="type-signature">(static) </span>remove<span class="signature">(path, params<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Deletes a file at given path.<br/>
Due to security reasons, paths are limited to the qz data directory unless overridden via properties file.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>path</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">Relative or absolute file path. Must reside in qz data directory or a white-listed location.</td>
</tr>
<tr>
<td class="name"><code>params</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Object containing file access parameters
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sandbox</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is only available to the certificate's connection, otherwise all connections</td>
</tr>
<tr>
<td class="name"><code>shared</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is accessible to all users on the system, otherwise just the current user</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2598">line 2598</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".setFileCallbacks"><span class="type-signature">(static) </span>setFileCallbacks<span class="signature">(calls)</span><span class="type-signature"></span></h4>
<div class="description">
List of functions called for any response from a file listener.
For ERROR types event data will contain, <code>{string} message</code>.
For ACTION types event data will contain, <code>{string} file {string} eventType {string} [data]</code>.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>calls</code></td>
<td class="type">
<span class="param-type">function</span>
|
<span class="param-type">Array.<function()></span>
</td>
<td class="description last">Single or array of <code>Function({Object} eventData)</code> calls.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>2.1.0</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2661">line 2661</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".startListening"><span class="type-signature">(static) </span>startListening<span class="signature">(path, params<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Provides a continuous stream of events (and optionally data) from a local file.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>path</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="description last">Relative or absolute directory path. Must reside in qz data directory or a white-listed location.</td>
</tr>
<tr>
<td class="name"><code>params</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Object containing file access parameters
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sandbox</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is only available to the certificate's connection, otherwise all connections</td>
</tr>
<tr>
<td class="name"><code>shared</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is accessible to all users on the system, otherwise just the current user</td>
</tr>
<tr>
<td class="name"><code>listener</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last">If defined, file data will be returned on events
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>bytes</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
-1
</td>
<td class="description last">Number of bytes to return or -1 for all</td>
</tr>
<tr>
<td class="name"><code>lines</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
-1
</td>
<td class="description last">Number of lines to return or -1 for all</td>
</tr>
<tr>
<td class="name"><code>reverse</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last">Controls whether data should be returned from the bottom of the file. Default value is true for line mode and false for byte mode.</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="name"><code>include</code></td>
<td class="type">
<span class="param-type">string</span>
|
<span class="param-type">Array.<string></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last">File patterns to match. Blank values will be ignored.</td>
</tr>
<tr>
<td class="name"><code>exclude</code></td>
<td class="type">
<span class="param-type">string</span>
|
<span class="param-type">Array.<string></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last">File patterns to exclude. Blank values will be ignored. Takes priority over <code>params.include</code>.</td>
</tr>
<tr>
<td class="name"><code>ignoreCase</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">Whether <code>params.include</code> or <code>params.exclude</code> are case-sensitive.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>2.1.0</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2624">line 2624</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li><a href="qz.file.html#.setFileCallbacks">qz.file.setFileCallbacks</a></li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".stopListening"><span class="type-signature">(static) </span>stopListening<span class="signature">(path<span class="signature-attributes">opt</span>, params<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Closes listeners with the provided settings. Omitting the path parameter will result in all listeners closing.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>path</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Previously opened directory path of listener to close, or omit to close all.</td>
</tr>
<tr>
<td class="name"><code>params</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Object containing file access parameters
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>sandbox</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is only available to the certificate's connection, otherwise all connections</td>
</tr>
<tr>
<td class="name"><code>shared</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is accessible to all users on the system, otherwise just the current user</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2646">line 2646</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".write"><span class="type-signature">(static) </span>write<span class="signature">(path, params)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Writes data to the file at the given path.<br/>
Due to security reasons, paths are limited to the qz data directory unless overridden via properties file.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>path</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last">Relative or absolute file path. Must reside in qz data directory or a white-listed location.</td>
</tr>
<tr>
<td class="name"><code>params</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Object containing file access parameters
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>data</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">File data to be written</td>
</tr>
<tr>
<td class="name"><code>sandbox</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is only available to the certificate's connection, otherwise all connections</td>
</tr>
<tr>
<td class="name"><code>shared</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If relative location from root is accessible to all users on the system, otherwise just the current user</td>
</tr>
<tr>
<td class="name"><code>append</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
false
</td>
<td class="description last">Appends to the end of the file if set, otherwise overwrites existing contents</td>
</tr>
<tr>
<td class="name"><code>flavor</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
'plain'
</td>
<td class="description last">Flavor of data format used, valid flavors are <code>[base64 | file | hex | plain]</code>.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line2581">line 2581</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="qz.html">qz</a></li><li><a href="qz.api.html">api</a></li><li><a href="qz.configs.html">configs</a></li><li><a href="qz.file.html">file</a></li><li><a href="qz.hid.html">hid</a></li><li><a href="qz.networking.html">networking</a></li><li><a href="qz.printers.html">printers</a></li><li><a href="qz.security.html">security</a></li><li><a href="qz.serial.html">serial</a></li><li><a href="qz.socket.html">socket</a></li><li><a href="qz.usb.html">usb</a></li><li><a href="qz.websocket.html">websocket</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Apr 02 2026 13:01:02 GMT-0400 (Eastern Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>