Skip to content

Commit

Permalink
Fix TypeScript definition and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rochars committed Aug 9, 2019
1 parent c617613 commit 394decf
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 38 deletions.
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ Read data from RIFF files.
npm install riff-file
```

## Use
```javascript
let wavFile = fs.readFileSync("file.wav");
let riff = new RIFFFile();
riff.setSignature(wavFile);
console.log(riff.signature);
```

The *signature* is an object representing the structure of the RIFF file. Chunks are listed in the *subChunks* property in the order they appear in the binary file. An example of what the signature of a RIFF WAVE file might look like:
```javascript
{
chunkId: 'RIFF',
chunkSize: 96096,
format: 'WAVE',
subChunks:
[
{
chunkId: 'fmt ',
chunkSize: 16,
chunkData: { start: 20, end: 36 }
},
{
chunkId: 'junk',
chunkSize: 52,
chunkData: { start: 44, end: 96 }
},
{
chunkId: 'data',
chunkSize: 96000,
chunkData: { start: 104, end: 96104 }
}
]
}
```

## API

### The RIFFFile methods
Expand All @@ -34,7 +69,7 @@ RIFFFile.fromBuffer = function(buffer) {};
* with the same chunkId.
* @return {Object}
*/
RIFFFile.toBitDepth = function(chunkId, multiple=false) {};
RIFFFile.findChunk = function(chunkId, multiple=false) {};
```

### The RIFFFile properties
Expand All @@ -45,20 +80,20 @@ RIFFFile.toBitDepth = function(chunkId, multiple=false) {};
*/
RIFFFile.container = '';
/**
* The main chunk size, in bytes.
* @type {number}
*/
RIFFFile.chunkSize = 0;
/**
* The format.
* Always WAVE.
* The format identifier.
* @type {string}
*/
RIFFFile.format = '';
/**
* A object defining the start and end of all chunks in a wav buffer.
* An object representing the signature of all chunks in the file.
* @type {!Object<string, *>}
*/
RIFFFile.junk = {
RIFFFile.signature = {
/** @type {string} */
chunkId: '',
/** @type {number} */
Expand Down
5 changes: 3 additions & 2 deletions dist/riff-file.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,16 +951,17 @@ class RIFFFile {
*/
this.container = '';
/**
* The main chunk size, in bytes.
* @type {number}
*/
this.chunkSize = 0;
/**
* The format.
* The format identifier.
* @type {string}
*/
this.format = '';
/**
* A object defining the start and end of all chunks in a wav buffer.
* An object representing the signature of all chunks in the file.
* @type {!Object}
*/
this.signature = {};
Expand Down
5 changes: 3 additions & 2 deletions dist/riff-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,16 +949,17 @@ class RIFFFile {
*/
this.container = '';
/**
* The main chunk size, in bytes.
* @type {number}
*/
this.chunkSize = 0;
/**
* The format.
* The format identifier.
* @type {string}
*/
this.format = '';
/**
* A object defining the start and end of all chunks in a wav buffer.
* An object representing the signature of all chunks in the file.
* @type {!Object}
*/
this.signature = {};
Expand Down
43 changes: 37 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module-ri
<h2>Install</h2>
<pre class="prettyprint source"><code>npm install riff-file
</code></pre>
<h2>Use</h2>
<pre class="prettyprint source lang-javascript"><code>let wavFile = fs.readFileSync(&quot;file.wav&quot;);
let riff = new RIFFFile();
riff.setSignature(wavFile);
console.log(riff.signature);
</code></pre>
<p>The <em>signature</em> is an object representing the structure of the RIFF file. Chunks are listed in the <em>subChunks</em> property in the order they appear in the binary file. An example of what the signature of a RIFF WAVE file might look like:</p>
<pre class="prettyprint source lang-javascript"><code>{
chunkId: 'RIFF',
chunkSize: 96096,
format: 'WAVE',
subChunks:
[
{
chunkId: 'fmt ',
chunkSize: 16,
chunkData: { start: 20, end: 36 }
},
{
chunkId: 'junk',
chunkSize: 52,
chunkData: { start: 44, end: 96 }
},
{
chunkId: 'data',
chunkSize: 96000,
chunkData: { start: 104, end: 96104 }
}
]
}
</code></pre>
<h2>API</h2>
<h3>The RIFFFile methods</h3>
<pre class="prettyprint source lang-javascript"><code>/**
Expand All @@ -75,7 +106,7 @@ <h3>The RIFFFile methods</h3>
* with the same chunkId.
* @return {Object}
*/
RIFFFile.toBitDepth = function(chunkId, multiple=false) {};
RIFFFile.findChunk = function(chunkId, multiple=false) {};
</code></pre>
<h3>The RIFFFile properties</h3>
<pre class="prettyprint source lang-javascript"><code>/**
Expand All @@ -84,20 +115,20 @@ <h3>The RIFFFile properties</h3>
*/
RIFFFile.container = '';
/**
* The main chunk size, in bytes.
* @type {number}
*/
RIFFFile.chunkSize = 0;
/**
* The format.
* Always WAVE.
* The format identifier.
* @type {string}
*/
RIFFFile.format = '';
/**
* A object defining the start and end of all chunks in a wav buffer.
* An object representing the signature of all chunks in the file.
* @type {!Object&lt;string, *>}
*/
RIFFFile.junk = {
RIFFFile.signature = {
/** @type {string} */
chunkId: '',
/** @type {number} */
Expand Down Expand Up @@ -247,7 +278,7 @@ <h2>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Fri Aug 09 2019 15:50:49 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Fri Aug 09 2019 16:31:01 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
7 changes: 4 additions & 3 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,17 @@ <h1 class="page-title">index.js</h1>
*/
this.container = '';
/**
* The main chunk size, in bytes.
* @type {number}
*/
this.chunkSize = 0;
/**
* The format.
* The format identifier.
* @type {string}
*/
this.format = '';
/**
* A object defining the start and end of all chunks in a wav buffer.
* An object representing the signature of all chunks in the file.
* @type {!Object}
*/
this.signature = {};
Expand Down Expand Up @@ -279,7 +280,7 @@ <h1 class="page-title">index.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Fri Aug 09 2019 15:50:49 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Fri Aug 09 2019 16:31:01 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
30 changes: 17 additions & 13 deletions docs/module-riff-file.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h4 class="name" id="chunkSize"><span class="type-signature"></span>chunkSize<sp

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line49">line 49</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line50">line 50</a>
</li></ul></dd>


Expand Down Expand Up @@ -200,6 +200,10 @@ <h4 class="name" id="chunkSize"><span class="type-signature"></span>chunkSize<sp



<div class="description">
The main chunk size, in bytes.
</div>



<h5>Type:</h5>
Expand Down Expand Up @@ -303,7 +307,7 @@ <h4 class="name" id="format"><span class="type-signature"></span>format<span cla

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line54">line 54</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line55">line 55</a>
</li></ul></dd>


Expand Down Expand Up @@ -343,7 +347,7 @@ <h4 class="name" id="format"><span class="type-signature"></span>format<span cla


<div class="description">
The format.
The format identifier.
</div>


Expand Down Expand Up @@ -376,7 +380,7 @@ <h4 class="name" id="head"><span class="type-signature">(protected) </span>head<

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line64">line 64</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line65">line 65</a>
</li></ul></dd>


Expand Down Expand Up @@ -445,7 +449,7 @@ <h4 class="name" id="signature"><span class="type-signature">(non-null) </span>s

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line59">line 59</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line60">line 60</a>
</li></ul></dd>


Expand Down Expand Up @@ -485,7 +489,7 @@ <h4 class="name" id="signature"><span class="type-signature">(non-null) </span>s


<div class="description">
A object defining the start and end of all chunks in a wav buffer.
An object representing the signature of all chunks in the file.
</div>


Expand Down Expand Up @@ -518,7 +522,7 @@ <h4 class="name" id="supported_containers"><span class="type-signature">(protect

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line76">line 76</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line77">line 77</a>
</li></ul></dd>


Expand Down Expand Up @@ -591,7 +595,7 @@ <h4 class="name" id="uInt32"><span class="type-signature">(protected, non-null)

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line69">line 69</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line70">line 70</a>
</li></ul></dd>


Expand Down Expand Up @@ -670,7 +674,7 @@ <h4 class="name" id="findChunk"><span class="type-signature">(protected) </span>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line110">line 110</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line111">line 111</a>
</li></ul></dd>


Expand Down Expand Up @@ -856,7 +860,7 @@ <h4 class="name" id="readString"><span class="type-signature">(protected) </span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line137">line 137</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line138">line 138</a>
</li></ul></dd>


Expand Down Expand Up @@ -1034,7 +1038,7 @@ <h4 class="name" id="readUInt32"><span class="type-signature">(protected) </span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line151">line 151</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line152">line 152</a>
</li></ul></dd>


Expand Down Expand Up @@ -1189,7 +1193,7 @@ <h4 class="name" id="setSignature"><span class="type-signature">(protected) </sp

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line84">line 84</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line85">line 85</a>
</li></ul></dd>


Expand Down Expand Up @@ -1323,7 +1327,7 @@ <h5>Parameters:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Fri Aug 09 2019 15:50:49 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Fri Aug 09 2019 16:31:01 GMT-0300 (Hora oficial do Brasil) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare class RIFFFile {
container: string;

/**
* The size of the main chunk.
* The main chunk size, in bytes.
* @type {number}
*/
chunkSize: number;
Expand All @@ -26,7 +26,7 @@ declare class RIFFFile {
format: string;

/**
* A object defining the start and end of all chunks in a wav buffer.
* An object representing the signature of all chunks in the file.
* @type {!Object<string, *>}
*/
signature: object;
Expand All @@ -38,11 +38,11 @@ declare class RIFFFile {
setSignature(bytes: Uint8Array): void;

/**
* Change the bit depth of the samples.
* Find a chunk by its fourCC_ in a array of RIFF chunks.
* @param {string} chunkId The chunk fourCC_.
* @param {boolean} multiple True if there may be multiple chunks
* with the same chunkId.
* @return {Object}
*/
findChunk(chunkId: string, multiple?: boolean): void;
findChunk(chunkId: string, multiple?: boolean): object;
}

0 comments on commit 394decf

Please sign in to comment.