From fe5154dd3b4c8fef09c6247ba3da9a1328de837d Mon Sep 17 00:00:00 2001 From: Rafael Rocha Date: Fri, 13 Jul 2018 03:47:33 -0300 Subject: [PATCH] Update API: export { riffChunks, findChunk }; --- CHANGELOG.md | 3 + README.md | 68 ++++++-- dist/README.md | 32 +++- dist/riff-chunks.cjs.js | 34 +++- dist/riff-chunks.js | 329 ++++++++++++++++++++-------------- dist/riff-chunks.min.js | 16 +- dist/riff-chunks.umd.js | 340 ++++++++++++++++++++++-------------- docs/index.html | 62 +++++-- docs/main.js.html | 36 +++- docs/module-riffChunks.html | 273 +++++++++++++++++++++++++---- main.js | 32 +++- package-lock.json | 16 +- package.json | 4 +- test/loader.js | 10 +- 14 files changed, 868 insertions(+), 387 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a431d13..7bb89eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## 9.0.0 (2018-07-13) +- API change: export {riffChunks, findChunk}. + ## 8.0.2 (2018-06-27) - Using only dot notation to allow better compilation on hosts. diff --git a/README.md b/README.md index 6be9786..5e81b20 100644 --- a/README.md +++ b/README.md @@ -14,25 +14,25 @@ npm install riff-chunks ## Use -### ES6 -```javascript -import riffChunks from 'riff-chunks'; -let chunks = riffChunks(riffFileBuffer); -``` - ### Node ```javascript -const riffChunks = require("riff-chunks"); +const riffChunks = require("riff-chunks").riffChunks; const fs = require("fs"); let chunks = riffChunks(fs.readFileSync("file.wav")); ``` +### ES6 +```javascript +import {riffChunks} from 'riff-chunks'; +let chunks = riffChunks(riffFileBuffer); +``` + ### Browser Use the compiled file in the */dist* folder: ```html ``` @@ -49,7 +49,7 @@ Or get it from [unpkg](https://www.unpkg.com): Or as a ES6 module in modern browsers from [jspm](https://jspm.io): ```html ``` @@ -60,10 +60,21 @@ Or as a ES6 module in modern browsers from [jspm](https://jspm.io): ```javascript /** * Return the chunks in a RIFF/RIFX file. - * @param {!Uint8Array|!Array} buffer The file bytes. + * @param {!Uint8Array} buffer The file bytes. * @return {!Object} The RIFF chunks. */ -function riffChunks(buffer) {} +export function riffChunks(buffer) {} + +/** + * Find a chunk by its fourCC_ in a array of RIFF chunks. + * @param {!Object} chunks The wav file chunks. + * @param {string} chunkId The chunk fourCC_. + * @param {boolean} multiple True if there may be multiple chunks + * with the same chunkId. + * @return {?Array} + * @private + */ +export function findChunk(chunks, chunkId, multiple=false) {} ``` **riffChunks()** returns a object like this: @@ -85,17 +96,36 @@ function riffChunks(buffer) {} } ``` -The **chunkData** field contains the raw bytes of the chunk data. - ## Distribution -This library is a ES6 module also distributed as a CommonJS module, UMD and a compiled script for browsers. +This library is a ES module also distributed as a CommonJS module, UMD module and a compiled script for browsers. It works out of the box in Node when installed with ```npm install riff-chunks```. + +### If you are using this lib in a browser: + +You may load both **./dist/riff-chunks.umd.js** and **./dist/riff-chunks.min.js** in the browser with ``` +``` + +[jsDelivr](https://cdn.jsdelivr.net/npm/riff-chunks): +```html + +``` + +### If you are using this lib as a dependency: + +- The **CommonJS** dist is **./dist/riff-chunks.cjs.js**. It is the dist file used by Node. It is served in the "main" field of package.json and is the source you are running when you **npm install riff-chunks**. It is not compiled or minified. + +- The **UMD** module is **./dist/riff-chunks.umd.js**. It is transpiled to ES5 and compatible with Node, AMD and browsers. It is served in the "browser" field of package.json. + +- The **browser-only** dist is **./dist/riff-chunks.min.js**. It is transpiled to ES5 and compiled. It is used in the "unpkg" and "jsdelivr" fields of package.json. + +- The **ES6 bundle** is **./dist/riff-chunks.js**, served as "es2015" in package.json. It is not compiled/minified. -- The **CommonJS** is the one used by Node. It is served in the "main" field of package.json -- The **UMD** module is compatible with Node, AMD and browsers. It is served in the "browser" field. -- The **compiled dist** is browser-only and should be the one served by CDNs. -- The **ES6** dist is **riff-chunks.js**, served as "module" in package.json +- **./main.js** is served as "module" in package.json. This should be the entry point for bundlers. -You may load both **riff-chunks.umd.js** and **riff-chunks.min.js** in the browser with ``` +``` + +[jsDelivr](https://cdn.jsdelivr.net/npm/riff-chunks): +```html + +``` + +## If you are using this lib as a dependency: + +- The **CommonJS** dist is **./dist/riff-chunks.cjs.js**. It is the dist file used by Node. It is served in the "main" field of package.json and is the source you are running when you **npm install riff-chunks**. It is not compiled or minified. + +- The **UMD** module is **./dist/riff-chunks.umd.js**. It is transpiled to ES5 and compatible with Node, AMD and browsers. It is served in the "browser" field of package.json. + +- The **browser-only** dist is **./dist/riff-chunks.min.js**. It is transpiled to ES5 and compiled. It is used in the "unpkg" and "jsdelivr" fields of package.json. + +- The **ES6 bundle** is **./dist/riff-chunks.js**, served as "es2015" in package.json. It is not compiled/minified. + +- **./main.js** is served as "module" in package.json. This should be the entry point for bundlers. + +If your module bundler is using "browser" as the entry point **your dist should work the same** but will be a larger file. diff --git a/dist/riff-chunks.cjs.js b/dist/riff-chunks.cjs.js index 2f6948c..63b01f2 100644 --- a/dist/riff-chunks.cjs.js +++ b/dist/riff-chunks.cjs.js @@ -1,11 +1,10 @@ 'use strict'; +Object.defineProperty(exports, '__esModule', { value: true }); + var byteData = require('byte-data'); /* - * riff-chunks: Read and write the chunks of RIFF and RIFX files. - * https://github.com/rochars/riff-chunks - * * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -53,6 +52,32 @@ function riffChunks(buffer) { }; } +/** + * Find a chunk by its fourCC_ in a array of RIFF chunks. + * @param {!Object} chunks The wav file chunks. + * @param {string} chunkId The chunk fourCC_. + * @param {boolean} multiple True if there may be multiple chunks + * with the same chunkId. + * @return {?Array} + */ +function findChunk(chunks, chunkId, multiple=false) { + /** @type {!Array} */ + let chunk = []; + for (let i=0; i|!Uint8Array} bytes The bytes. + * @param {number} offset The byte offset. + * @param {number=} index The start index. Assumes 0. + * @param {number=} end The end index. Assumes the buffer length. + * @throws {Error} If the buffer length is not valid. + */ +function endianness(bytes, offset, index=0, end=bytes.length) { + if (end % offset) { + throw new Error("Bad buffer length."); + } + for (; index < end; index += offset) { + swap(bytes, offset, index); + } +} + +/** + * Swap the byte order of a value in a buffer. The buffer is modified in place. + * @param {!Array|!Uint8Array} bytes The bytes. + * @param {number} offset The byte offset. + * @param {number} index The start index. + * @private + */ +function swap(bytes, offset, index) { + offset--; + for(let x = 0; x < offset; x++) { + /** @type {number|string} */ + let theByte = bytes[index + x]; + bytes[index + x] = bytes[index + offset]; + bytes[index + offset] = theByte; + offset--; + } +} + +/* * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -27,6 +88,7 @@ /** * @fileoverview Pack and unpack two's complement ints and unsigned ints. + * @see https://github.com/rochars/byte-data */ /** @@ -43,26 +105,31 @@ class Integer { /** * The max number of bits used by the data. * @type {number} + * @private */ this.bits = bits; /** * If this type it is signed or not. * @type {boolean} + * @private */ this.signed = signed; /** * The number of bytes used by the data. * @type {number} + * @private */ this.offset = 0; /** * Min value for numbers of this type. * @type {number} + * @private */ this.min = -Infinity; /** * Max value for numbers of this type. * @type {number} + * @private */ this.max = Infinity; /** @@ -253,9 +320,6 @@ class Integer { } /* - * endianness: Swap endianness in byte arrays. - * https://github.com/rochars/endianness - * * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -280,80 +344,21 @@ class Integer { */ /** - * @fileoverview A function to swap endianness in byte buffers. - */ - -/** - * @module endianness + * @fileoverview Functions to validate input. + * @see https://github.com/rochars/byte-data */ /** - * Swap the byte ordering in a buffer. The buffer is modified in place. - * @param {!Array|!Uint8Array} bytes The bytes. - * @param {number} offset The byte offset. - * @param {number=} start The start index. Assumes 0. - * @param {?number=} end The end index. Assumes the buffer length. - * @throws {Error} If the buffer length is not valid. + * Validate that the code is a valid ASCII code. + * @param {number} code The code. + * @throws {Error} If the code is not a valid ASCII code. */ -function endianness(bytes, offset, start=0, end=null) { - let len = end || bytes.length; - let limit = parseInt(offset / 2, 10); - if (len % offset) { - throw new Error("Bad buffer length."); - } - let i = start; - while (i < len) { - swap(bytes, offset, i, limit); - i += offset; - } -} - -/** - * Swap the byte order of a value in a buffer. The buffer is modified in place. - * @param {!Array|!Uint8Array} bytes The bytes. - * @param {number} offset The byte offset. - * @param {number} index The start index. - * @private - */ -function swap(bytes, offset, index, limit) { - let x = 0; - let y = offset - 1; - while(x < limit) { - let theByte = bytes[index + x]; - bytes[index + x] = bytes[index + y]; - bytes[index + y] = theByte; - x++; - y--; - } +function validateASCIICode(code) { + if (code > 127) { + throw new Error ('Bad ASCII code.'); + } } -/* - * byte-data: Pack and unpack binary data. - * https://github.com/rochars/byte-data - * - * Copyright (c) 2017-2018 Rafael da Silva Rocha. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - /** * Validate the type definition. * @param {!Object} theType The type definition. @@ -395,9 +400,6 @@ function validateIntType_(theType) { } /* - * byte-data: Pack and unpack binary data. - * https://github.com/rochars/byte-data - * * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -421,63 +423,36 @@ function validateIntType_(theType) { * */ -// Strings -/** - * Read a string from a byte buffer. - * @param {!Uint8Array} bytes A byte buffer. - * @param {number=} index The index to read. - * @param {?number=} len The number of bytes to read. - * @return {string} - */ -function unpackString(bytes, index=0, len=null) { - let chrs = ''; - len = len || bytes.length - index; - for(let j = 0; j < len; j++) { - chrs += String.fromCharCode(bytes[index+j]); - } - return chrs; -} - /** - * Unpack a number from a byte buffer by index. - * @param {!Uint8Array} buffer The byte buffer. - * @param {!Object} theType The type definition. - * @param {number=} index The buffer index to read. - * @return {number} - * @throws {Error} If the type definition is not valid + * Use a Typed Array to check if the host is BE or LE. This will impact + * on how 64-bit floating point numbers are handled. + * @type {boolean} + * @private */ -function unpackFrom(buffer, theType, index=0) { - setUp_(theType); - if (theType.be) { - endianness(buffer, theType.offset, index, index + theType.offset); - } - let value = reader_(buffer, index); - if (theType.be) { - endianness(buffer, theType.offset, index, index + theType.offset); - } - return value; -} +const BE_ENV = new Uint8Array(new Uint32Array([0x12345678]).buffer)[0] === 0x12; +const HIGH = BE_ENV ? 1 : 0; +const LOW = BE_ENV ? 0 : 1; /** * @type {!Int8Array} * @private */ -const int8_ = new Int8Array(8); +let int8_ = new Int8Array(8); /** * @type {!Uint32Array} * @private */ -const ui32_ = new Uint32Array(int8_.buffer); +let ui32_ = new Uint32Array(int8_.buffer); /** * @type {!Float32Array} * @private */ -const f32_ = new Float32Array(int8_.buffer); +let f32_ = new Float32Array(int8_.buffer); /** * @type {!Float64Array} * @private */ -const f64_ = new Float64Array(int8_.buffer); +let f64_ = new Float64Array(int8_.buffer); /** * @type {Function} * @private @@ -489,6 +464,23 @@ let reader_; */ let gInt_ = {}; +/** + * Validate the type and set up the packing/unpacking functions. + * @param {!Object} theType The type definition. + * @throws {Error} If the type definition is not valid. + * @private + */ +function setUp_(theType) { + validateType(theType); + theType.offset = theType.bits < 8 ? 1 : Math.ceil(theType.bits / 8); + theType.be = theType.be || false; + setReader(theType); + setWriter(theType); + gInt_ = new Integer( + theType.bits == 64 ? 32 : theType.bits, + theType.float ? false : theType.signed); +} + /** * Read int values from bytes. * @param {!Uint8Array} bytes An array of bytes. @@ -509,9 +501,13 @@ function readInt_(bytes, i) { * @private */ function read16F_(bytes, i) { + /** @type {number} */ let int = gInt_.read(bytes, i); + /** @type {number} */ let exponent = (int & 0x7C00) >> 10; + /** @type {number} */ let fraction = int & 0x03FF; + /** @type {number} */ let floatValue; if (exponent) { floatValue = Math.pow(2, exponent - 15) * (1 + fraction / 0x400); @@ -542,8 +538,8 @@ function read32F_(bytes, i) { * @private */ function read64F_(bytes, i) { - ui32_[0] = gInt_.read(bytes, i); - ui32_[1] = gInt_.read(bytes, i + 4); + ui32_[HIGH] = gInt_.read(bytes, i); + ui32_[LOW] = gInt_.read(bytes, i + 4); return f64_[0]; } @@ -577,26 +573,71 @@ function setWriter(theType) { } } +/* + * Copyright (c) 2017-2018 Rafael da Silva Rocha. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +// ASCII characters +/** + * Read a string of ASCII characters from a byte buffer. + * @param {!Uint8Array} bytes A byte buffer. + * @param {number=} index The index to read. + * @param {?number=} len The number of bytes to read. + * @return {string} + * @throws {Error} If a character in the string is not valid ASCII. + */ +function unpackString(bytes, index=0, len=null) { + let chrs = ''; + len = len ? index + len : bytes.length; + while (index < len) { + validateASCIICode(bytes[index]); + chrs += String.fromCharCode(bytes[index]); + index++; + } + return chrs; +} + /** - * Validate the type and set up the packing/unpacking functions. + * Unpack a number from a byte buffer by index. + * @param {!Uint8Array} buffer The byte buffer. * @param {!Object} theType The type definition. - * @throws {Error} If the type definition is not valid. - * @private + * @param {number=} index The buffer index to read. + * @return {number} + * @throws {Error} If the type definition is not valid */ -function setUp_(theType) { - validateType(theType); - theType.offset = theType.bits < 8 ? 1 : Math.ceil(theType.bits / 8); - setReader(theType); - setWriter(theType); - gInt_ = new Integer( - theType.bits == 64 ? 32 : theType.bits, - theType.float ? false : theType.signed); +function unpackFrom(buffer, theType, index=0) { + setUp_(theType); + if (theType.be) { + endianness(buffer, theType.offset, index, index + theType.offset); + } + let value = reader_(buffer, index); + if (theType.be) { + endianness(buffer, theType.offset, index, index + theType.offset); + } + return value; } /* - * riff-chunks: Read and write the chunks of RIFF and RIFX files. - * https://github.com/rochars/riff-chunks - * * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -644,6 +685,32 @@ function riffChunks(buffer) { }; } +/** + * Find a chunk by its fourCC_ in a array of RIFF chunks. + * @param {!Object} chunks The wav file chunks. + * @param {string} chunkId The chunk fourCC_. + * @param {boolean} multiple True if there may be multiple chunks + * with the same chunkId. + * @return {?Array} + */ +function findChunk(chunks, chunkId, multiple=false) { + /** @type {!Array} */ + let chunk = []; + for (let i=0; i>10;var c=b&1023;return(a?Math.pow(2, -a-15)*(1+c/1024):c/1024*.00006103515625)*(b>>15?-1:1)}function v(b,a){m[0]=k.read(b,a);return w[0]}function x(b,a){m[0]=k.read(b,a);m[1]=k.read(b,a+4);return y[0]}function q(b){for(var a=[],c=f;c<=b.length-8;)a.push(z(b,c)),c+=8+a[a.length-1].chunkSize,c=c%2?c+1:c;return a}function z(b,a){f+=4;var c={chunkId:h(b,a,4),chunkSize:r(b,a)};"LIST"==c.chunkId?(c.format=h(b,a+8,4),f+=4,c.subChunks=q(b)):(f=a+8+(c.chunkSize%2?c.chunkSize+1:c.chunkSize),c.chunkData={start:a+8,end:f});return c}function r(b, -a){f+=4;a+=4;a=void 0===a?0:a;if(!d)throw Error("Undefined type.");if(d.float){if(-1==[16,32,64].indexOf(d.bits))throw Error("Bad float type.");}else if(1>d.bits||53d.bits?1:Math.ceil(d.bits/8);d.float?16==d.bits?g=u:32==d.bits?g=v:64==d.bits&&(g=x):g=t;k=new e(64==d.bits?32:d.bits,d.float?!1:d.signed);d.be&&p(b,d.offset,a,a+d.offset);var c=g(b,a);d.be&&p(b,d.offset,a,a+d.offset);return c}var e=function(b,a){this.bits=b;this.signed=a;this.offset= -0;this.min=-Infinity;this.max=Infinity;this.realBits_=this.bits;this.lastByteMask_=255;this.build_()};e.prototype.read=function(b,a){a=void 0===a?0:a;for(var c=0,d=this.offset-1;0>>0;return this.overflow_(this.sign_(c))};e.prototype.write=function(b,a,c){c=void 0===c?0:c;a=this.overflow_(a);b[c++]=a&255;for(var d=2;d<=this.offset;d++)b[c++]=Math.floor(a/Math.pow(2,8*(d-1)))&255;return c};e.prototype.writeEsoteric_=function(b,a,c){c=void 0===c?0:c;a=this.overflow_(a); -c=this.writeFirstByte_(b,a,c);for(var d=2;dthis.bits?1:Math.ceil(this.realBits_/8);if(this.realBits_!=this.bits||8>this.bits||32this.max&&(b-=2*this.max+2);return b};e.prototype.overflow_=function(b){if(b>this.max)throw Error("Overflow.");if(bthis.bits?b[c++]=0>a?a+Math.pow(2,this.bits):a:b[c++]=a&255;return c};var n=new Int8Array(8),m=new Uint32Array(n.buffer),w=new Float32Array(n.buffer),y=new Float64Array(n.buffer),g,k={},d={bits:32},f=0;return function(b){f=0;f+=4;var a=h(b,0,4);d.be="RIFX"==a;var c=h(b,8,4);f+= -4;return{chunkId:a,chunkSize:r(b,0),format:c,subChunks:q(b)}}}();window.riffChunks=riffChunks; +var riffChunks=function(n){function q(b,a,c,k){c=void 0===c?0:c;k=void 0===k?b.length:k;if(k%a)throw Error("Bad buffer length.");for(;c>10;var c=b&1023;return(a?Math.pow(2,a-15)*(1+c/1024):c/1024*.00006103515625)*(b>>15?-1:1)}function w(b,a){p[0]=g.read(b,a);return x[0]}function y(b,a){p[z]=g.read(b,a);p[A]=g.read(b,a+4);return B[0]} +function m(b,a,c){a=void 0===a?0:a;c=void 0===c?null:c;var d="";for(c=c?a+c:b.length;ad.bits||53d.bits?1:Math.ceil(d.bits/8);d.be=d.be||!1;d.float?16==d.bits?l=v:32==d.bits?l=w:64==d.bits&&(l=y):l=u;g=new e(64==d.bits?32:d.bits,d.float?!1:d.signed);d.be&&q(b,d.offset,a,a+d.offset);var c=l(b,a);d.be&&q(b,d.offset,a,a+d.offset);return c}var e=function(b,a){this.bits= +b;this.signed=a;this.offset=0;this.min=-Infinity;this.max=Infinity;this.realBits_=this.bits;this.lastByteMask_=255;this.build_()};e.prototype.read=function(b,a){a=void 0===a?0:a;for(var c=0,d=this.offset-1;0>>0;return this.overflow_(this.sign_(c))};e.prototype.write=function(b,a,c){c=void 0===c?0:c;a=this.overflow_(a);b[c++]=a&255;for(var d=2;d<=this.offset;d++)b[c++]=Math.floor(a/Math.pow(2,8*(d-1)))&255;return c};e.prototype.writeEsoteric_=function(b,a,c){c=void 0=== +c?0:c;a=this.overflow_(a);c=this.writeFirstByte_(b,a,c);for(var d=2;dthis.bits?1:Math.ceil(this.realBits_/8);if(this.realBits_!=this.bits||8>this.bits||32this.max&&(b-=2*this.max+2);return b};e.prototype.overflow_=function(b){if(b>this.max)throw Error("Overflow.");if(bthis.bits?b[c++]=0>a?a+Math.pow(2,this.bits):a:b[c++]=a&255;return c};var h=18===(new Uint8Array((new Uint32Array([305419896])).buffer))[0],z=h?1:0,A=h?0:1;h=new Int8Array(8);var p=new Uint32Array(h.buffer),x=new Float32Array(h.buffer),B=new Float64Array(h.buffer),l,g={},d={bits:32}, +f=0;n.riffChunks=function(b){f=0;f+=4;var a=m(b,0,4);d.be="RIFX"==a;var c=m(b,8,4);f+=4;return{chunkId:a,chunkSize:t(b,0),format:c,subChunks:r(b)}};n.findChunk=function(b,a,c){c=void 0===c?!1:c;for(var d=[],e=0;e|!Uint8Array} bytes The bytes. + * @param {number} offset The byte offset. + * @param {number=} index The start index. Assumes 0. + * @param {number=} end The end index. Assumes the buffer length. + * @throws {Error} If the buffer length is not valid. + */ + function endianness(bytes, offset, index=0, end=bytes.length) { + if (end % offset) { + throw new Error("Bad buffer length."); + } + for (; index < end; index += offset) { + swap(bytes, offset, index); + } + } + + /** + * Swap the byte order of a value in a buffer. The buffer is modified in place. + * @param {!Array|!Uint8Array} bytes The bytes. + * @param {number} offset The byte offset. + * @param {number} index The start index. + * @private + */ + function swap(bytes, offset, index) { + offset--; + for(let x = 0; x < offset; x++) { + /** @type {number|string} */ + let theByte = bytes[index + x]; + bytes[index + x] = bytes[index + offset]; + bytes[index + offset] = theByte; + offset--; + } + } + + /* * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -33,6 +94,7 @@ /** * @fileoverview Pack and unpack two's complement ints and unsigned ints. + * @see https://github.com/rochars/byte-data */ /** @@ -49,26 +111,31 @@ /** * The max number of bits used by the data. * @type {number} + * @private */ this.bits = bits; /** * If this type it is signed or not. * @type {boolean} + * @private */ this.signed = signed; /** * The number of bytes used by the data. * @type {number} + * @private */ this.offset = 0; /** * Min value for numbers of this type. * @type {number} + * @private */ this.min = -Infinity; /** * Max value for numbers of this type. * @type {number} + * @private */ this.max = Infinity; /** @@ -259,9 +326,6 @@ } /* - * endianness: Swap endianness in byte arrays. - * https://github.com/rochars/endianness - * * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -286,80 +350,21 @@ */ /** - * @fileoverview A function to swap endianness in byte buffers. + * @fileoverview Functions to validate input. + * @see https://github.com/rochars/byte-data */ /** - * @module endianness + * Validate that the code is a valid ASCII code. + * @param {number} code The code. + * @throws {Error} If the code is not a valid ASCII code. */ - - /** - * Swap the byte ordering in a buffer. The buffer is modified in place. - * @param {!Array|!Uint8Array} bytes The bytes. - * @param {number} offset The byte offset. - * @param {number=} start The start index. Assumes 0. - * @param {?number=} end The end index. Assumes the buffer length. - * @throws {Error} If the buffer length is not valid. - */ - function endianness(bytes, offset, start=0, end=null) { - let len = end || bytes.length; - let limit = parseInt(offset / 2, 10); - if (len % offset) { - throw new Error("Bad buffer length."); - } - let i = start; - while (i < len) { - swap(bytes, offset, i, limit); - i += offset; - } - } - - /** - * Swap the byte order of a value in a buffer. The buffer is modified in place. - * @param {!Array|!Uint8Array} bytes The bytes. - * @param {number} offset The byte offset. - * @param {number} index The start index. - * @private - */ - function swap(bytes, offset, index, limit) { - let x = 0; - let y = offset - 1; - while(x < limit) { - let theByte = bytes[index + x]; - bytes[index + x] = bytes[index + y]; - bytes[index + y] = theByte; - x++; - y--; - } + function validateASCIICode(code) { + if (code > 127) { + throw new Error ('Bad ASCII code.'); + } } - /* - * byte-data: Pack and unpack binary data. - * https://github.com/rochars/byte-data - * - * Copyright (c) 2017-2018 Rafael da Silva Rocha. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - /** * Validate the type definition. * @param {!Object} theType The type definition. @@ -401,9 +406,6 @@ } /* - * byte-data: Pack and unpack binary data. - * https://github.com/rochars/byte-data - * * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -427,63 +429,36 @@ * */ - // Strings /** - * Read a string from a byte buffer. - * @param {!Uint8Array} bytes A byte buffer. - * @param {number=} index The index to read. - * @param {?number=} len The number of bytes to read. - * @return {string} - */ - function unpackString(bytes, index=0, len=null) { - let chrs = ''; - len = len || bytes.length - index; - for(let j = 0; j < len; j++) { - chrs += String.fromCharCode(bytes[index+j]); - } - return chrs; - } - - /** - * Unpack a number from a byte buffer by index. - * @param {!Uint8Array} buffer The byte buffer. - * @param {!Object} theType The type definition. - * @param {number=} index The buffer index to read. - * @return {number} - * @throws {Error} If the type definition is not valid + * Use a Typed Array to check if the host is BE or LE. This will impact + * on how 64-bit floating point numbers are handled. + * @type {boolean} + * @private */ - function unpackFrom(buffer, theType, index=0) { - setUp_(theType); - if (theType.be) { - endianness(buffer, theType.offset, index, index + theType.offset); - } - let value = reader_(buffer, index); - if (theType.be) { - endianness(buffer, theType.offset, index, index + theType.offset); - } - return value; - } + const BE_ENV = new Uint8Array(new Uint32Array([0x12345678]).buffer)[0] === 0x12; + const HIGH = BE_ENV ? 1 : 0; + const LOW = BE_ENV ? 0 : 1; /** * @type {!Int8Array} * @private */ - const int8_ = new Int8Array(8); + let int8_ = new Int8Array(8); /** * @type {!Uint32Array} * @private */ - const ui32_ = new Uint32Array(int8_.buffer); + let ui32_ = new Uint32Array(int8_.buffer); /** * @type {!Float32Array} * @private */ - const f32_ = new Float32Array(int8_.buffer); + let f32_ = new Float32Array(int8_.buffer); /** * @type {!Float64Array} * @private */ - const f64_ = new Float64Array(int8_.buffer); + let f64_ = new Float64Array(int8_.buffer); /** * @type {Function} * @private @@ -495,6 +470,23 @@ */ let gInt_ = {}; + /** + * Validate the type and set up the packing/unpacking functions. + * @param {!Object} theType The type definition. + * @throws {Error} If the type definition is not valid. + * @private + */ + function setUp_(theType) { + validateType(theType); + theType.offset = theType.bits < 8 ? 1 : Math.ceil(theType.bits / 8); + theType.be = theType.be || false; + setReader(theType); + setWriter(theType); + gInt_ = new Integer( + theType.bits == 64 ? 32 : theType.bits, + theType.float ? false : theType.signed); + } + /** * Read int values from bytes. * @param {!Uint8Array} bytes An array of bytes. @@ -515,9 +507,13 @@ * @private */ function read16F_(bytes, i) { + /** @type {number} */ let int = gInt_.read(bytes, i); + /** @type {number} */ let exponent = (int & 0x7C00) >> 10; + /** @type {number} */ let fraction = int & 0x03FF; + /** @type {number} */ let floatValue; if (exponent) { floatValue = Math.pow(2, exponent - 15) * (1 + fraction / 0x400); @@ -548,8 +544,8 @@ * @private */ function read64F_(bytes, i) { - ui32_[0] = gInt_.read(bytes, i); - ui32_[1] = gInt_.read(bytes, i + 4); + ui32_[HIGH] = gInt_.read(bytes, i); + ui32_[LOW] = gInt_.read(bytes, i + 4); return f64_[0]; } @@ -583,26 +579,71 @@ } } + /* + * Copyright (c) 2017-2018 Rafael da Silva Rocha. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + + // ASCII characters + /** + * Read a string of ASCII characters from a byte buffer. + * @param {!Uint8Array} bytes A byte buffer. + * @param {number=} index The index to read. + * @param {?number=} len The number of bytes to read. + * @return {string} + * @throws {Error} If a character in the string is not valid ASCII. + */ + function unpackString(bytes, index=0, len=null) { + let chrs = ''; + len = len ? index + len : bytes.length; + while (index < len) { + validateASCIICode(bytes[index]); + chrs += String.fromCharCode(bytes[index]); + index++; + } + return chrs; + } + /** - * Validate the type and set up the packing/unpacking functions. + * Unpack a number from a byte buffer by index. + * @param {!Uint8Array} buffer The byte buffer. * @param {!Object} theType The type definition. - * @throws {Error} If the type definition is not valid. - * @private + * @param {number=} index The buffer index to read. + * @return {number} + * @throws {Error} If the type definition is not valid */ - function setUp_(theType) { - validateType(theType); - theType.offset = theType.bits < 8 ? 1 : Math.ceil(theType.bits / 8); - setReader(theType); - setWriter(theType); - gInt_ = new Integer( - theType.bits == 64 ? 32 : theType.bits, - theType.float ? false : theType.signed); + function unpackFrom(buffer, theType, index=0) { + setUp_(theType); + if (theType.be) { + endianness(buffer, theType.offset, index, index + theType.offset); + } + let value = reader_(buffer, index); + if (theType.be) { + endianness(buffer, theType.offset, index, index + theType.offset); + } + return value; } /* - * riff-chunks: Read and write the chunks of RIFF and RIFX files. - * https://github.com/rochars/riff-chunks - * * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -650,6 +691,32 @@ }; } + /** + * Find a chunk by its fourCC_ in a array of RIFF chunks. + * @param {!Object} chunks The wav file chunks. + * @param {string} chunkId The chunk fourCC_. + * @param {boolean} multiple True if there may be multiple chunks + * with the same chunkId. + * @return {?Array} + */ + function findChunk(chunks, chunkId, multiple=false) { + /** @type {!Array} */ + let chunk = []; + for (let i=0; i
@@ -49,25 +49,36 @@

Home

Modules

  • NPM version Docs
    Codecov Unix Build Windows Build Scrutinizer

    Parse the chunks of RIFF and RIFX files.

    -

    Install

    npm install riff-chunks

    Use

    ES6

    import riffChunks from 'riff-chunks';
    -let chunks = riffChunks(riffFileBuffer);

    Node

    const riffChunks = require("riff-chunks");
    +

    Install

    npm install riff-chunks

    Use

    Node

    const riffChunks = require("riff-chunks").riffChunks;
     const fs = require("fs");
    -let chunks = riffChunks(fs.readFileSync("file.wav"));

    Browser

    Use the compiled file in the /dist folder:

    +let chunks = riffChunks(fs.readFileSync("file.wav"));

    ES6

    import {riffChunks} from 'riff-chunks';
    +let chunks = riffChunks(riffFileBuffer);

    Browser

    Use the compiled file in the /dist folder:

    <script src="riff-chunks.min.js"></script>
     <script>
    -var chunks = riffChunks(riffFileBuffer);
    +var chunks = riffChunks.riffChunks(riffFileBuffer);
     </script>

    Or get it from the jsDelivr CDN:

    <script src="https://cdn.jsdelivr.net/npm/riff-chunks@8"></script>

    Or get it from unpkg:

    <script src="https://unpkg.com/riff-chunks@8"></script>

    Or as a ES6 module in modern browsers from jspm:

    <script type="module">
    -  import riffChunks from 'https://dev.jspm.io/riff-chunks';
    +  import {riffChunks} from 'https://dev.jspm.io/riff-chunks';
       // ...
     </script>

    API

    riffChunks(buffer)

    /**
      * Return the chunks in a RIFF/RIFX file.
    - * @param {!Uint8Array|!Array<number>} buffer The file bytes.
    + * @param {!Uint8Array} buffer The file bytes.
      * @return {!Object} The RIFF chunks.
      */
    -function riffChunks(buffer) {}

    riffChunks() returns a object like this:

    +export function riffChunks(buffer) {} + +/** + * Find a chunk by its fourCC_ in a array of RIFF chunks. + * @param {!Object} chunks The wav file chunks. + * @param {string} chunkId The chunk fourCC_. + * @param {boolean} multiple True if there may be multiple chunks + * with the same chunkId. + * @return {?Array<!Object>} + * @private + */ +export function findChunk(chunks, chunkId, multiple=false) {}

    riffChunks() returns a object like this:

    {
         "chunkId": string,
         "chunkSize": number,
    @@ -82,15 +93,23 @@ 

    Install

    npm install riff-chunks

    The chunkData field contains the raw bytes of the chunk data.

    -

    Distribution

    This library is a ES6 module also distributed as a CommonJS module, UMD and a compiled script for browsers.

    -
      -
    • The CommonJS is the one used by Node. It is served in the "main" field of package.json
    • -
    • The UMD module is compatible with Node, AMD and browsers. It is served in the "browser" field.
    • -
    • The compiled dist is browser-only and should be the one served by CDNs.
    • -
    • The ES6 dist is riff-chunks.js, served as "module" in package.json
    • +}

    Distribution

    This library is a ES module also distributed as a CommonJS module, UMD module and a compiled script for browsers. It works out of the box in Node when installed with npm install riff-chunks.

    +

    If you are using this lib in a browser:

    You may load both ./dist/riff-chunks.umd.js and ./dist/riff-chunks.min.js in the browser with <script> tags. Ideally you should use riff-chunks.min.js. You can load it via the https://unpkg.com and https://www.jsdelivr.com/ CDNs:

    +

    unpkg:

    +
    <script src="https://unpkg.com/riff-chunks"></script>

    jsDelivr:

    +
    <script src="https://cdn.jsdelivr.net/npm/riff-chunks"></script>

    If you are using this lib as a dependency:

      +
    • The CommonJS dist is ./dist/riff-chunks.cjs.js. It is the dist file used by Node. It is served in the "main" field of package.json and is the source you are running when you npm install riff-chunks. It is not compiled or minified.

      +
    • +
    • The UMD module is ./dist/riff-chunks.umd.js. It is transpiled to ES5 and compatible with Node, AMD and browsers. It is served in the "browser" field of package.json.

      +
    • +
    • The browser-only dist is ./dist/riff-chunks.min.js. It is transpiled to ES5 and compiled. It is used in the "unpkg" and "jsdelivr" fields of package.json.

      +
    • +
    • The ES6 bundle is ./dist/riff-chunks.js, served as "es2015" in package.json. It is not compiled/minified.

      +
    • +
    • ./main.js is served as "module" in package.json. This should be the entry point for bundlers.

      +
    -

    You may load both riff-chunks.umd.js and riff-chunks.min.js in the browser with <script> tags.

    +

    If your module bundler is using "browser" as the entry point your dist should work the same but will be a larger file.

    LICENSE

    Copyright (c) 2017-2018 Rafael da Silva Rocha.

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -139,7 +158,7 @@

    Source:
    @@ -169,6 +188,13 @@

    + +
    See:
    +
    + +
    @@ -214,7 +240,7 @@


    - Documentation generated by JSDoc 3.5.5 on Wed Jun 27 2018 04:24:35 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Fri Jul 13 2018 03:46:48 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
    diff --git a/docs/main.js.html b/docs/main.js.html index 368ed68..059476d 100644 --- a/docs/main.js.html +++ b/docs/main.js.html @@ -22,7 +22,7 @@
    @@ -38,9 +38,6 @@

    main.js

    /*
    - * riff-chunks: Read and write the chunks of RIFF and RIFX files.
    - * https://github.com/rochars/riff-chunks
    - *
      * Copyright (c) 2017-2018 Rafael da Silva Rocha.
      *
      * Permission is hereby granted, free of charge, to any person obtaining
    @@ -66,6 +63,7 @@ 

    main.js

    /** * @fileoverview The riff-chunks API. + * @see https://github.com/rochars/riff-chunks */ /** @module riffChunks */ @@ -82,7 +80,7 @@

    main.js

    * @param {!Uint8Array} buffer The file bytes. * @return {!Object} The RIFF chunks. */ -export default function riffChunks(buffer) { +export function riffChunks(buffer) { head_ = 0; let chunkId = getChunkId_(buffer, 0); uInt32_.be = chunkId == 'RIFX'; @@ -96,6 +94,32 @@

    main.js

    }; } +/** + * Find a chunk by its fourCC_ in a array of RIFF chunks. + * @param {!Object} chunks The wav file chunks. + * @param {string} chunkId The chunk fourCC_. + * @param {boolean} multiple True if there may be multiple chunks + * with the same chunkId. + * @return {?Array<!Object>} + */ +export function findChunk(chunks, chunkId, multiple=false) { + /** @type {!Array<!Object>} */ + let chunk = []; + for (let i=0; i<chunks.length; i++) { + if (chunks[i].chunkId == chunkId) { + if (multiple) { + chunk.push(chunks[i]); + } else { + return chunks[i]; + } + } + } + if (chunkId == 'LIST') { + return chunk.length ? chunk : null; + } + return null; +} + /** * Return the sub chunks of a RIFF file. * @param {!Uint8Array} buffer the RIFF file bytes. @@ -176,7 +200,7 @@

    main.js


    - Documentation generated by JSDoc 3.5.5 on Wed Jun 27 2018 04:24:35 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Fri Jul 13 2018 03:46:48 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
    diff --git a/docs/module-riffChunks.html b/docs/module-riffChunks.html index 169c007..680ac0b 100644 --- a/docs/module-riffChunks.html +++ b/docs/module-riffChunks.html @@ -22,7 +22,7 @@
    @@ -40,8 +40,6 @@

    riffChunks

    - -
    @@ -51,11 +49,103 @@

    riffChunks

    + +
    + + + + + + + + + + + + +

    Members

    + + +

    (inner) head_ :number

    + + + + +
    + + +
    Source:
    +
    -

    (require("riffChunks"))(buffernon-null) → (non-null) {Object}

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + +
    Type:
    +
      +
    • + +number + + +
    • +
    + + + + + + + + + + +

    Methods

    + + + + + + +

    (static) findChunk(chunksnon-null, chunkId, multiple) → (nullable) {Array.<!Object>}

    @@ -67,7 +157,7 @@

    (req
    Source:
    @@ -107,7 +197,7 @@

    (req
    - Return the chunks in a RIFF/RIFX file. + Find a chunk by its fourCC_ in a array of RIFF chunks.
    @@ -145,13 +235,13 @@

    Parameters:
    - buffer + chunks -Uint8Array +Object @@ -161,7 +251,53 @@
    Parameters:
    - The file bytes. + The wav file chunks. + + + + + + + chunkId + + + + + +string + + + + + + + + + + The chunk fourCC_. + + + + + + + multiple + + + + + +boolean + + + + + + + + + + True if there may be multiple chunks with the same chunkId. @@ -184,10 +320,6 @@
    Parameters:
    Returns:
    -
    - The RIFF chunks. -
    -
    @@ -196,7 +328,7 @@
    Returns:
    -Object +Array.<!Object>
    @@ -206,26 +338,13 @@
    Returns:
    - -
    - - - - + - - - +

    (static) riffChunks(buffernon-null) → (non-null) {Object}

    -

    Members

    - - - -

    (inner) head_ :number

    - @@ -235,7 +354,7 @@

    (inner) head_Source:
    @@ -274,26 +393,106 @@

    (inner) head_ + Return the chunks in a RIFF/RIFX file. +

+ -
Type:
-
    -
  • + + + + + + + + +
    Parameters:
    + + + + + + + + + + + + + + + + + + + + + + + + + -number + + + + + + + + + + + + +
    NameTypeDescription
    buffer + + +Uint8Array + + + + The file bytes.
    + + + + + -
  • -
+ +
Returns:
+ +
+ The RIFF chunks. +
+ + + +
+
+ Type +
+
+ +Object + + +
+
+ + + @@ -311,7 +510,7 @@
Type:

- Documentation generated by JSDoc 3.5.5 on Wed Jun 27 2018 04:24:35 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Fri Jul 13 2018 03:46:48 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/main.js b/main.js index c38d7b2..d305c76 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,4 @@ /* - * riff-chunks: Read and write the chunks of RIFF and RIFX files. - * https://github.com/rochars/riff-chunks - * * Copyright (c) 2017-2018 Rafael da Silva Rocha. * * Permission is hereby granted, free of charge, to any person obtaining @@ -27,6 +24,7 @@ /** * @fileoverview The riff-chunks API. + * @see https://github.com/rochars/riff-chunks */ /** @module riffChunks */ @@ -43,7 +41,7 @@ let head_ = 0; * @param {!Uint8Array} buffer The file bytes. * @return {!Object} The RIFF chunks. */ -export default function riffChunks(buffer) { +export function riffChunks(buffer) { head_ = 0; let chunkId = getChunkId_(buffer, 0); uInt32_.be = chunkId == 'RIFX'; @@ -57,6 +55,32 @@ export default function riffChunks(buffer) { }; } +/** + * Find a chunk by its fourCC_ in a array of RIFF chunks. + * @param {!Object} chunks The wav file chunks. + * @param {string} chunkId The chunk fourCC_. + * @param {boolean} multiple True if there may be multiple chunks + * with the same chunkId. + * @return {?Array} + */ +export function findChunk(chunks, chunkId, multiple=false) { + /** @type {!Array} */ + let chunk = []; + for (let i=0; i", @@ -63,6 +63,6 @@ "rollup-plugin-node-resolve": "^3.3.0" }, "dependencies": { - "byte-data": "^13.0.1" + "byte-data": "^13.2.5" } } diff --git a/test/loader.js b/test/loader.js index aa942c9..a9a88e5 100644 --- a/test/loader.js +++ b/test/loader.js @@ -11,27 +11,27 @@ if (process.argv[3] == '--min') { console.log('browser'); require('browser-env')(); require('../dist/riff-chunks.min.js'); - riffChunks = window.riffChunks; + riffChunks = window.riffChunks.riffChunks; // UMD } else if (process.argv[3] == '--umd') { console.log('umd'); - riffChunks = require('../dist/riff-chunks.umd.js'); + riffChunks = require('../dist/riff-chunks.umd.js').riffChunks; // CommonJS } else if (process.argv[3] == '--cjs') { console.log('cjs'); - riffChunks = require('../dist/riff-chunks.cjs.js'); + riffChunks = require('../dist/riff-chunks.cjs.js').riffChunks; // ESM } else if (process.argv[3] == '--esm') { console.log('esm'); - riffChunks = require('../dist/riff-chunks.js').default; + riffChunks = require('../dist/riff-chunks.js').riffChunks; // Source } else { console.log('Source tests'); - riffChunks = require('../main.js').default; + riffChunks = require('../main.js').riffChunks; } module.exports = riffChunks;