diff --git a/dist/riff-chunks-min.js b/dist/riff-chunks-min.js index 0f10d80..3dfe544 100644 --- a/dist/riff-chunks-min.js +++ b/dist/riff-chunks-min.js @@ -1,13 +1,13 @@ -(function(a){function c(d){if(b[d])return b[d].a;var f=b[d]={V:d,C:!1,a:{}};a[d].call(f.a,f,f.a,c);f.C=!0;return f.a}var b={};c.u=a;c.h=b;c.b=function(a,b){c.f(a)||Object.defineProperty(a,"a",{configurable:!1,enumerable:!0,get:b})};c.j=function(a){var b=a&&a.L?function(){return a["default"]}:function(){return a};c.b(b,b);return b};c.f=function(a){return Object.prototype.hasOwnProperty.call(a,"a")};c.l="";return c(c.v=0)})([function(a,c,b){a=b(1);window.riffChunks=window.riffChunks?window.riffChunks: -{};window.riffChunks.read=a.read;window.riffChunks.write=a.write},function(a,c,b){function d(a){k.be="RIFX"===a.chunkId;var b=e.m(a.chunkId,e.c).concat(e.w(a.chunkSize,k),e.m(a.format,e.c),f(a.subChunks));if("RIFF"===a.chunkId||"RIFX"===a.chunkId)b=new Uint8Array(b);return b}function f(a){for(var b=[],c=0;c>10;var c=a&1023;return(b?Math.pow(2,b-15)*(1+c/1024):c/1024*.00006103515625)*(a>>15?-1:1)}function g(a,b){v[0]=l.read(a,b);return w[0]}function h(a,b){q[0]=l.read(a,b);q[1]=l.read(a,b+4);return x[0]}function e(a,b){for(var c="",m=0;m>16&32768;var d=m>>12&2047;m=m>>23&255;103<= -m&&(b=(b|m-112<<10|d>>1)+(d&1));a[c++]=b&255;a[c++]=b>>>8&255;return c}function u(a,b,c){w[0]=b;return c=l.write(a,v[0],c)}function z(a,b,c){x[0]=b;c=l.write(a,q[0],c);return l.write(a,q[1],c)}function A(a,b,c){a[c++]=b.charCodeAt(0);return c}var y=b(4),r=b(5);c=new Int8Array(4);var v=new Int32Array(c.buffer,0,1),w=new Float32Array(c.buffer,0,1);c=new Int8Array(8);var x=new Float64Array(c.buffer),q=new Uint32Array(c.buffer),n,p,l;a.a.o=function(a,b){for(var c=0,d=[],f=0;fa.bits?1:Math.ceil(a.bits/8);a.base=b;a["float"]?16==a.bits?n=f:32==a.bits?n=g:64==a.bits&&(n=h):a["char"]?n=e:n=d;a["float"]?16==a.bits?p=t:32==a.bits?p=u:64==a.bits&&(p=z):a["char"]?p=A:p=k;l=a["float"]?64==a.bits?new r(32,!1):32==a.bits?new r(32,!0):new r(16,!1):new r(a.bits,a.signed)}},function(a){a.a=function(a,b){for(var c=a.length,f=0;f>>0;return this.f(this.l(b))};c.prototype.write=function(a,c,f){c=this.f(c);var b=255;f=this.K(a,c,void 0===f?0:f);for(var d=2;d<=this.offset;d++)d==this.offset&&(b=this.j),a[f++]=Math.floor(c/Math.pow(2,8*(d-1)))&b;return f};c.prototype.v=function(a, -c){c=void 0===c?0:c;for(var b="",d=0;dthis.b?1:Math.ceil(this.h/8)};c.prototype.l=function(a){a>this.max&&(a-=2*this.max+2);return a};c.prototype.f=function(a){a>this.max?a=this.max:athis.b||64this.b?a[f++]=0>c?c+Math.pow(2,this.b):c:a[f++]=c&255;return f};a.a=c}]); \ No newline at end of file +(function(a){function c(d){if(b[d])return b[d].a;var f=b[d]={N:d,o:!1,a:{}};a[d].call(f.a,f,f.a,c);f.o=!0;return f.a}var b={};c.l=a;c.h=b;c.b=function(a,b){c.f(a)||Object.defineProperty(a,"a",{configurable:!1,enumerable:!0,get:b})};c.i=function(a){var b=a&&a.C?function(){return a["default"]}:function(){return a};c.b(b,b);return b};c.f=function(a){return Object.prototype.hasOwnProperty.call(a,"a")};c.j="";return c(c.m=0)})([function(a,c,b){a=b(1);window.riffChunks=window.riffChunks?window.riffChunks: +{};window.riffChunks.read=a.read;window.riffChunks.write=a.write},function(a,c,b){function d(a){k.be="RIFX"==a.chunkId;var b=h.g(a.chunkId,m).concat(h.g(a.chunkSize,k),h.g(a.format,m),f(a.subChunks));if("RIFF"==a.chunkId||"RIFX"==a.chunkId)b=new Uint8Array(b);return b}function f(a){for(var b=[],c=0;c>10;var e=a&1023;return(b? +Math.pow(2,b-15)*(1+e/1024):e/1024*.00006103515625)*(a>>15?-1:1)}function h(a,b){q[0]=l.read(a,b);return x[0]}function k(a,b){q[0]=l.read(a,b);q[1]=l.read(a,b+4);return z[0]}function m(a,b){for(var e="",c=0;c>16&32768;var g=e>>12&2047;e=e>>23&255;103<=e&&(b=(b|e-112<<10|g>>1)+(g&1));a[c++]=b&255;a[c++]=b>>>8&255;return c}function C(a,b,c){x[0]=b;return l.write(a,q[0], +c)}function D(a,b,c){z[0]=b;c=l.write(a,q[0],c);return l.write(a,q[1],c)}function E(a,b,c){for(var e=0;ea.bits||a.bits%2)throw Error("Wrong offset for type char.");}else if(1>a.bits||53a.bits?1:Math.ceil(a.bits/8);a["float"]?16==a.bits? +r=n:32==a.bits?r=h:64==a.bits&&(r=k):a["char"]?r=m:r=p;a["float"]?16==a.bits?t=B:32==a.bits?t=C:64==a.bits&&(t=D):a["char"]?t=E:t=v;a["char"]?l.offset=8>a.bits?1:Math.ceil(a.bits/8):l=new F(64==a.bits?32:a.bits,a["float"]?!1:a.signed)}function A(a,b){a.constructor==String&&(a=a.length>=b.offset?a.slice(0,b.offset):"");return a}var y=b(3),F=b(4);c=new Int8Array(8);var q=new Uint32Array(c.buffer),x=new Float32Array(c.buffer),z=new Float64Array(c.buffer),r,t,l={};a.a.F={bits:8,"char":!0};a.a.M={bits:32, +"char":!0};a.a.D={bits:1};a.a.R={bits:2,signed:!0};a.a.ea={bits:2};a.a.W={bits:4,signed:!0};a.a.ja={bits:4};a.a.aa={bits:8,signed:!0};a.a.oa={bits:8};a.a.O={bits:16,signed:!0};a.a.ca={bits:16};a.a.G={bits:16,"float":!0};a.a.S={bits:24,signed:!0};a.a.fa={bits:24};a.a.U={bits:32,signed:!0};a.a.ha={bits:32};a.a.I={bits:32,"float":!0};a.a.X={bits:40,signed:!0};a.a.ka={bits:40};a.a.Z={bits:48,signed:!0};a.a.ma={bits:48};a.a.K={bits:64,"float":!0};a.a.P={bits:16,signed:!0,be:!0};a.a.da={bits:16,be:!0}; +a.a.H={bits:16,"float":!0,be:!0};a.a.T={bits:24,signed:!0,be:!0};a.a.ga={bits:24,be:!0};a.a.V={bits:32,signed:!0,be:!0};a.a.ia={bits:32,be:!0};a.a.J={bits:32,"float":!0,be:!0};a.a.Y={bits:40,signed:!0,be:!0};a.a.la={bits:40,be:!0};a.a.$={bits:48,signed:!0,be:!0};a.a.na={bits:48,be:!0};a.a.L={bits:64,"float":!0,be:!0};a.a.g=function(a,b){var c=void 0===c?10:c;u(b);var d=[];if(void 0===a)return d;a=A(a,b);return f([a],b,c)};a.a.c=function(a,b){var c=void 0===c?10:c;u(b);return(a=d(a.slice(0,b.offset), +b,c))?a[0]:b["char"]?"":null};a.a.ba=function(a,b,c){c=void 0===c?10:c;u(b);if(b["char"])for(var d=a.length,e=0;e>>0;return this.f(this.j(b))};c.prototype.write=function(a,c,f){c=this.f(c);var b=255;f=this.B(a,c,void 0===f?0:f);for(var d=2;d<=this.offset;d++)d==this.offset&&(b=this.i),a[f++]=Math.floor(c/Math.pow(2,8*(d-1)))&b;return f};c.prototype.m=function(a,c){c=void 0===c?0:c;for(var b="",d=0;dthis.b?1:Math.ceil(this.h/8)};c.prototype.j=function(a){a>this.max&&(a-=2*this.max+2);return a};c.prototype.f=function(a){a>this.max?a=this.max:athis.b||64this.b?a[f++]=0>c?c+Math.pow(2,this.b):c:a[f++]=c&255;return f};a.a=c}]); \ No newline at end of file diff --git a/docs/global.html b/docs/global.html index 50d8ce9..886905f 100644 --- a/docs/global.html +++ b/docs/global.html @@ -115,7 +115,7 @@

Methods

-

read(buffer) → {Object}

+

read(buffer) → (non-null) {Object}

@@ -127,7 +127,7 @@

readSource:
@@ -214,7 +214,7 @@
Parameters:
Uint8Array | -Array.<number> +!Array.<number> @@ -273,7 +273,7 @@
Returns:
-

write(chunks) → {Uint8Array}

+

write(chunksnon-null) → {!Array.<number>|Uint8Array}

@@ -285,7 +285,7 @@

writeSource:
@@ -403,7 +403,7 @@
Returns:
- The file bytes as Uint8Array when chunkId is "RIFF" or "RIFX" or the chunk bytes as Array when chunkId is "LIST". + The bytes as Uint8Array when chunkId is "RIFF" or "RIFX" or the chunk bytes as Array when chunkId is "LIST".
@@ -414,6 +414,9 @@
Returns:
+!Array.<number> +| + Uint8Array @@ -441,7 +444,7 @@
Returns:

- Documentation generated by JSDoc 3.5.5 on Thu May 03 2018 23:19:51 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Sat May 05 2018 21:25:48 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/docs/index.html b/docs/index.html index a6bdff4..94ffc51 100644 --- a/docs/index.html +++ b/docs/index.html @@ -105,7 +105,7 @@

riffChunks.write()


 
 
- Documentation generated by JSDoc 3.5.5 on Thu May 03 2018 23:19:51 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Sat May 05 2018 21:25:48 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/docs/index.js.html b/docs/index.js.html index 311ca6f..8ddd0f5 100644 --- a/docs/index.js.html +++ b/docs/index.js.html @@ -48,24 +48,25 @@

index.js

/** @private */ const byteData = require("byte-data"); /** @private */ -let uInt32 = byteData.uInt32; +const uInt32_ = {"bits": 32}; +/** @private */ +const fourCC_ = {"bits": 32, "char": true}; /** * Write the bytes of a RIFF/RIFX file. - * @param {Object} chunks A structure like the return of riffChunks.read(). - * @return {Uint8Array} The file bytes as Uint8Array when - * chunkId is "RIFF" or "RIFX" or the chunk bytes as Array<number> - * when chunkId is "LIST". + * @param {!Object} chunks A structure like the return of riffChunks.read(). + * @return {!Array<number>|Uint8Array} The bytes as Uint8Array when chunkId is + * "RIFF" or "RIFX" or the chunk bytes as Array<number> when chunkId is "LIST". */ function write(chunks) { - uInt32["be"] = chunks["chunkId"] === "RIFX"; + uInt32_["be"] = chunks["chunkId"] == "RIFX"; let bytes = - byteData.packArray(chunks["chunkId"], byteData.chr).concat( - byteData.pack(chunks["chunkSize"], uInt32), - byteData.packArray(chunks["format"], byteData.chr), + byteData.pack(chunks["chunkId"], fourCC_).concat( + byteData.pack(chunks["chunkSize"], uInt32_), + byteData.pack(chunks["format"], fourCC_), writeSubChunks_(chunks["subChunks"]) ); - if (chunks["chunkId"] === "RIFF" || chunks["chunkId"] === "RIFX" ) { + if (chunks["chunkId"] == "RIFF" || chunks["chunkId"] == "RIFX" ) { bytes = new Uint8Array(bytes); } return bytes; @@ -73,37 +74,37 @@

index.js

/** * Get the chunks of a RIFF/RIFX file. - * @param {Uint8Array|Array<number>} buffer The file bytes. - * @return {Object} The chunk. + * @param {!Uint8Array|!Array<number>} buffer The file bytes. + * @return {!Object} The chunk. */ function read(buffer) { buffer = [].slice.call(buffer); let chunkId = getChunkId_(buffer, 0); - uInt32["be"] = chunkId === "RIFX"; + uInt32_["be"] = chunkId == "RIFX"; return { "chunkId": chunkId, "chunkSize": getChunkSize_(buffer, 0), - "format": byteData.unpackArray(buffer.slice(8, 12), byteData.chr), + "format": byteData.unpack(buffer.slice(8, 12), fourCC_), "subChunks": getSubChunks_(buffer) }; } /** * Write the sub chunks of a RIFF file. - * @param {Array<Object>} chunks The chunks. - * @return {Array<number>} The chunk bytes. + * @param {!Array<!Object>} chunks The chunks. + * @return {!Array<number>} The chunk bytes. * @private */ function writeSubChunks_(chunks) { let subChunks = []; let i = 0; while (i < chunks.length) { - if (chunks[i]["chunkId"] === "LIST") { + if (chunks[i]["chunkId"] == "LIST") { subChunks = subChunks.concat(write(chunks[i])); } else { subChunks = subChunks.concat( - byteData.packArray(chunks[i]["chunkId"], byteData.chr), - byteData.pack(chunks[i]["chunkSize"], uInt32), + byteData.pack(chunks[i]["chunkId"], fourCC_), + byteData.pack(chunks[i]["chunkSize"], uInt32_), chunks[i]["chunkData"] ); } @@ -114,8 +115,8 @@

index.js

/** * Get the sub chunks of a RIFF file. - * @param {Uint8Array|Array<number>} buffer the RIFF file bytes. - * @return {Object} The subchunks of a RIFF/RIFX or LIST chunk. + * @param {!Uint8Array|!Array<number>} buffer the RIFF file bytes. + * @return {!Array<Object>} The subchunks of a RIFF/RIFX or LIST chunk. * @private */ function getSubChunks_(buffer) { @@ -130,18 +131,20 @@

index.js

/** * Get a sub chunk from a RIFF file. - * @param {Uint8Array|Array<number>} buffer the RIFF file bytes. - * @param {number} index The start index of the chunk. - * @return {Object} A subchunk of a RIFF/RIFX or LIST chunk. + * @param {!Uint8Array|!Array<number>} buffer the RIFF file bytes. + * @param {!number} index The start index of the chunk. + * @return {!Object} A subchunk of a RIFF/RIFX or LIST chunk. * @private */ function getSubChunk_(buffer, index) { let chunk = { "chunkId": getChunkId_(buffer, index), - "chunkSize": getChunkSize_(buffer, index) + "chunkSize": getChunkSize_(buffer, index), + "subChunks": [], + "chunkData": [] }; - if (chunk["chunkId"] === "LIST") { - chunk["format"] = byteData.unpackArray(buffer.slice(8, 12), byteData.chr); + if (chunk["chunkId"] == "LIST") { + chunk["format"] = byteData.unpack(buffer.slice(8, 12), fourCC_); chunk["subChunks"] = getSubChunks_( buffer.slice(index, index + chunk["chunkSize"])); } else { @@ -152,25 +155,25 @@

index.js

} /** - * Return the FourCC of a chunk. - * @param {Uint8Array|Array<number>} buffer the RIFF file bytes. - * @param {number} index The start index of the chunk. - * @return {string} The id of the chunk. + * Return the fourCC_ of a chunk. + * @param {!Uint8Array|!Array<number>} buffer the RIFF file bytes. + * @param {!number} index The start index of the chunk. + * @return {!string} The id of the chunk. * @private */ function getChunkId_(buffer, index) { - return byteData.unpackArray(buffer.slice(index, index + 4), byteData.chr); + return byteData.unpack(buffer.slice(index, index + 4), fourCC_); } /** * Return the size of a chunk. - * @param {Uint8Array|Array<number>} buffer the RIFF file bytes. - * @param {number} index The start index of the chunk. - * @return {number} The size of the chunk without the id and size fields. + * @param {!Uint8Array|!Array<number>} buffer the RIFF file bytes. + * @param {!number} index The start index of the chunk. + * @return {!number} The size of the chunk without the id and size fields. * @private */ function getChunkSize_(buffer, index) { - return byteData.unpack(buffer.slice(index + 4, index + 8), uInt32); + return byteData.unpack(buffer.slice(index + 4, index + 8), uInt32_); } module.exports.read = read; @@ -187,7 +190,7 @@

index.js


- Documentation generated by JSDoc 3.5.5 on Thu May 03 2018 23:19:51 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Sat May 05 2018 21:25:48 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/index.js b/index.js index 4686056..adc6bc6 100644 --- a/index.js +++ b/index.js @@ -9,24 +9,25 @@ /** @private */ const byteData = require("byte-data"); /** @private */ -let uInt32 = byteData.uInt32; +const uInt32_ = {"bits": 32}; +/** @private */ +const fourCC_ = {"bits": 32, "char": true}; /** * Write the bytes of a RIFF/RIFX file. - * @param {Object} chunks A structure like the return of riffChunks.read(). - * @return {Uint8Array} The file bytes as Uint8Array when - * chunkId is "RIFF" or "RIFX" or the chunk bytes as Array - * when chunkId is "LIST". + * @param {!Object} chunks A structure like the return of riffChunks.read(). + * @return {!Array|Uint8Array} The bytes as Uint8Array when chunkId is + * "RIFF" or "RIFX" or the chunk bytes as Array when chunkId is "LIST". */ function write(chunks) { - uInt32["be"] = chunks["chunkId"] === "RIFX"; + uInt32_["be"] = chunks["chunkId"] == "RIFX"; let bytes = - byteData.packArray(chunks["chunkId"], byteData.chr).concat( - byteData.pack(chunks["chunkSize"], uInt32), - byteData.packArray(chunks["format"], byteData.chr), + byteData.pack(chunks["chunkId"], fourCC_).concat( + byteData.pack(chunks["chunkSize"], uInt32_), + byteData.pack(chunks["format"], fourCC_), writeSubChunks_(chunks["subChunks"]) ); - if (chunks["chunkId"] === "RIFF" || chunks["chunkId"] === "RIFX" ) { + if (chunks["chunkId"] == "RIFF" || chunks["chunkId"] == "RIFX" ) { bytes = new Uint8Array(bytes); } return bytes; @@ -34,37 +35,37 @@ function write(chunks) { /** * Get the chunks of a RIFF/RIFX file. - * @param {Uint8Array|Array} buffer The file bytes. - * @return {Object} The chunk. + * @param {!Uint8Array|!Array} buffer The file bytes. + * @return {!Object} The chunk. */ function read(buffer) { buffer = [].slice.call(buffer); let chunkId = getChunkId_(buffer, 0); - uInt32["be"] = chunkId === "RIFX"; + uInt32_["be"] = chunkId == "RIFX"; return { "chunkId": chunkId, "chunkSize": getChunkSize_(buffer, 0), - "format": byteData.unpackArray(buffer.slice(8, 12), byteData.chr), + "format": byteData.unpack(buffer.slice(8, 12), fourCC_), "subChunks": getSubChunks_(buffer) }; } /** * Write the sub chunks of a RIFF file. - * @param {Array} chunks The chunks. - * @return {Array} The chunk bytes. + * @param {!Array} chunks The chunks. + * @return {!Array} The chunk bytes. * @private */ function writeSubChunks_(chunks) { let subChunks = []; let i = 0; while (i < chunks.length) { - if (chunks[i]["chunkId"] === "LIST") { + if (chunks[i]["chunkId"] == "LIST") { subChunks = subChunks.concat(write(chunks[i])); } else { subChunks = subChunks.concat( - byteData.packArray(chunks[i]["chunkId"], byteData.chr), - byteData.pack(chunks[i]["chunkSize"], uInt32), + byteData.pack(chunks[i]["chunkId"], fourCC_), + byteData.pack(chunks[i]["chunkSize"], uInt32_), chunks[i]["chunkData"] ); } @@ -75,8 +76,8 @@ function writeSubChunks_(chunks) { /** * Get the sub chunks of a RIFF file. - * @param {Uint8Array|Array} buffer the RIFF file bytes. - * @return {Object} The subchunks of a RIFF/RIFX or LIST chunk. + * @param {!Uint8Array|!Array} buffer the RIFF file bytes. + * @return {!Array} The subchunks of a RIFF/RIFX or LIST chunk. * @private */ function getSubChunks_(buffer) { @@ -91,18 +92,20 @@ function getSubChunks_(buffer) { /** * Get a sub chunk from a RIFF file. - * @param {Uint8Array|Array} buffer the RIFF file bytes. - * @param {number} index The start index of the chunk. - * @return {Object} A subchunk of a RIFF/RIFX or LIST chunk. + * @param {!Uint8Array|!Array} buffer the RIFF file bytes. + * @param {!number} index The start index of the chunk. + * @return {!Object} A subchunk of a RIFF/RIFX or LIST chunk. * @private */ function getSubChunk_(buffer, index) { let chunk = { "chunkId": getChunkId_(buffer, index), - "chunkSize": getChunkSize_(buffer, index) + "chunkSize": getChunkSize_(buffer, index), + "subChunks": [], + "chunkData": [] }; - if (chunk["chunkId"] === "LIST") { - chunk["format"] = byteData.unpackArray(buffer.slice(8, 12), byteData.chr); + if (chunk["chunkId"] == "LIST") { + chunk["format"] = byteData.unpack(buffer.slice(8, 12), fourCC_); chunk["subChunks"] = getSubChunks_( buffer.slice(index, index + chunk["chunkSize"])); } else { @@ -113,25 +116,25 @@ function getSubChunk_(buffer, index) { } /** - * Return the FourCC of a chunk. - * @param {Uint8Array|Array} buffer the RIFF file bytes. - * @param {number} index The start index of the chunk. - * @return {string} The id of the chunk. + * Return the fourCC_ of a chunk. + * @param {!Uint8Array|!Array} buffer the RIFF file bytes. + * @param {!number} index The start index of the chunk. + * @return {!string} The id of the chunk. * @private */ function getChunkId_(buffer, index) { - return byteData.unpackArray(buffer.slice(index, index + 4), byteData.chr); + return byteData.unpack(buffer.slice(index, index + 4), fourCC_); } /** * Return the size of a chunk. - * @param {Uint8Array|Array} buffer the RIFF file bytes. - * @param {number} index The start index of the chunk. - * @return {number} The size of the chunk without the id and size fields. + * @param {!Uint8Array|!Array} buffer the RIFF file bytes. + * @param {!number} index The start index of the chunk. + * @return {!number} The size of the chunk without the id and size fields. * @private */ function getChunkSize_(buffer, index) { - return byteData.unpack(buffer.slice(index + 4, index + 8), uInt32); + return byteData.unpack(buffer.slice(index + 4, index + 8), uInt32_); } module.exports.read = read; diff --git a/package.json b/package.json index 03b9849..76d2707 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "riff-chunks", - "version": "4.0.1", + "version": "4.0.2", "description": "Read and write the chunks of RIFF and RIFX files.", "homepage": "https://github.com/rochars/riff-chunks", "author": "Rafael da Silva Rocha ", @@ -45,6 +45,6 @@ }, "main": "index.js", "dependencies": { - "byte-data": "^7.0.0" + "byte-data": "^8.0.0" } }