diff --git a/CHANGELOG.md b/CHANGELOG.md index b663cbb..5e8b34e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # CHANGELOG +## 4.0.6 (2018-06-10) +- fix: chunkSize for odd number of bytes. + ## 4.0.5 (2018-05-13) - Better packaging. diff --git a/dist/riff-chunks-min.js b/dist/riff-chunks-min.js index 0bed9a3..21a27ef 100644 --- a/dist/riff-chunks-min.js +++ b/dist/riff-chunks-min.js @@ -1,13 +1,13 @@ (function(a){function e(d){if(b[d])return b[d].a;var c=b[d]={O:d,s:!1,a:{}};a[d].call(c.a,c,c.a,e);c.s=!0;return c.a}var b={};e.l=a;e.g=b;e.b=function(a,b){e.c(a)||Object.defineProperty(a,"a",{configurable:!1,enumerable:!0,get:b})};e.i=function(a){var b=a&&a.D?function(){return a["default"]}:function(){return a};e.b(b,b);return b};e.c=function(a){return Object.prototype.hasOwnProperty.call(a,"a")};e.j="";return e(e.m=0)})([function(a,e,b){a=b(1);window.riffChunks=a;window.riffChunks.read=a.read;window.riffChunks.write= -a.write},function(a,e,b){function d(a,b){b=void 0===b?!1:b;n.be="RIFX"==a.chunkId;a=h.h(a.chunkId,l).concat(h.h(a.chunkSize,n),h.h(a.format,l),c(a.subChunks));b||(a=new Uint8Array(a));return a}function c(a){for(var b=[],c=0;c>10;var f=a&1023;return(b?Math.pow(2,b-15)*(1+f/1024): -f/1024*.00006103515625)*(a>>15?-1:1)}function q(a,b){r[0]=k.read(a,b);return x[0]}function h(a,b){r[0]=k.read(a,b);r[1]=k.read(a,b+4);return z[0]}function n(a,b){for(var f="",c=0;c>16&32768;var d=f>>12&2047;f=f>>23&255;103<=f&&(b=(b|f-112<<10|d>>1)+(d&1));a[c++]=b&255;a[c++]=b>>>8&255;return c}function C(a,b,c){x[0]=b;return k.write(a,r[0],c)}function D(a,b,c){z[0]= -b;c=k.write(a,r[0],c);return k.write(a,r[1],c)}function E(a,b,c){for(var f=0;fa.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?t=m:32==a.bits?t=q:64== -a.bits&&(t=h):a["char"]?t=n:t=p;a["float"]?16==a.bits?u=B:32==a.bits?u=C:64==a.bits&&(u=D):a["char"]?u=E:u=l;a["char"]?k.offset=8>a.bits?1:Math.ceil(a.bits/8):k=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);e=new Int8Array(8);var r=new Uint32Array(e.buffer),x=new Float32Array(e.buffer),z=new Float64Array(e.buffer),t,u,k={};a.a.G={bits:8,"char":!0};a.a.N={bits:32,"char":!0};a.a.F={bits:1}; -a.a.S={bits:2,signed:!0};a.a.fa={bits:2};a.a.X={bits:4,signed:!0};a.a.ka={bits:4};a.a.ba={bits:8,signed:!0};a.a.pa={bits:8};a.a.P={bits:16,signed:!0};a.a.da={bits:16};a.a.H={bits:16,"float":!0};a.a.T={bits:24,signed:!0};a.a.ga={bits:24};a.a.V={bits:32,signed:!0};a.a.ia={bits:32};a.a.J={bits:32,"float":!0};a.a.Y={bits:40,signed:!0};a.a.la={bits:40};a.a.$={bits:48,signed:!0};a.a.na={bits:48};a.a.L={bits:64,"float":!0};a.a.R={bits:16,signed:!0,be:!0};a.a.ea={bits:16,be:!0};a.a.I={bits:16,"float":!0, -be:!0};a.a.U={bits:24,signed:!0,be:!0};a.a.ha={bits:24,be:!0};a.a.W={bits:32,signed:!0,be:!0};a.a.ja={bits:32,be:!0};a.a.K={bits:32,"float":!0,be:!0};a.a.Z={bits:40,signed:!0,be:!0};a.a.ma={bits:40,be:!0};a.a.aa={bits:48,signed:!0,be:!0};a.a.oa={bits:48,be:!0};a.a.M={bits:64,"float":!0,be:!0};a.a.h=function(a,b){var d=void 0===d?10:d;v(b);var e=[];if(void 0===a)return e;a=A(a,b);return c([a],b,d)};a.a.f=function(a,b){var c=void 0===c?10:c;v(b);return(a=d(a.slice(0,b.offset),b,c))?a[0]:b["char"]?"": -null};a.a.ca=function(a,b,d){d=void 0===d?10:d;v(b);if(b["char"])for(var e=a.length,p=0;p>>0;return this.c(this.j(b))};e.prototype.write=function(a,d,c){c=void 0===c?0:c;d=this.c(d);a[c++]=d&255;for(var b=2;b<=this.offset;b++)a[c++]=Math.floor(d/Math.pow(2,8*(b-1)))&255;return c};e.prototype.C=function(a,d,c){d=this.c(d);c=this.o(a,d,void 0===c?0:c);for(var b=2;bthis.b?1:Math.ceil(this.g/8);if(this.g!=this.b||8>this.b||32this.max&&(a-=2*this.max+2);return a};e.prototype.c=function(a){a>this.max?a=this.max:athis.b||64this.b?a[c++]=0>d?d+Math.pow(2,this.b):d:a[c++]=d&255;return c};a.a=e}]); \ No newline at end of file +a.write},function(a,e,b){function d(a,b){b=void 0===b?!1:b;k.be="RIFX"==a.chunkId;a=g.h(a.chunkId,m).concat(g.h(a.chunkSize,k),g.h(a.format,m),c(a.subChunks));b||(a=new Uint8Array(a));return a}function c(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){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 c="",f=0;f>16&32768;var d=f>>12&2047;f=f>>23&255;103<=f&&(b=(b|f-112<<10|d>>1)+(d&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 f=0;fa.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=g: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);e=new Int8Array(8);var q=new Uint32Array(e.buffer),x=new Float32Array(e.buffer),z=new Float64Array(e.buffer),r,t,l={};a.a.G={bits:8,"char":!0};a.a.N={bits:32,"char":!0};a.a.F={bits:1};a.a.S={bits:2,signed:!0};a.a.fa={bits:2}; +a.a.X={bits:4,signed:!0};a.a.ka={bits:4};a.a.ba={bits:8,signed:!0};a.a.pa={bits:8};a.a.P={bits:16,signed:!0};a.a.da={bits:16};a.a.H={bits:16,"float":!0};a.a.T={bits:24,signed:!0};a.a.ga={bits:24};a.a.V={bits:32,signed:!0};a.a.ia={bits:32};a.a.J={bits:32,"float":!0};a.a.Y={bits:40,signed:!0};a.a.la={bits:40};a.a.$={bits:48,signed:!0};a.a.na={bits:48};a.a.L={bits:64,"float":!0};a.a.R={bits:16,signed:!0,be:!0};a.a.ea={bits:16,be:!0};a.a.I={bits:16,"float":!0,be:!0};a.a.U={bits:24,signed:!0,be:!0};a.a.ha= +{bits:24,be:!0};a.a.W={bits:32,signed:!0,be:!0};a.a.ja={bits:32,be:!0};a.a.K={bits:32,"float":!0,be:!0};a.a.Z={bits:40,signed:!0,be:!0};a.a.ma={bits:40,be:!0};a.a.aa={bits:48,signed:!0,be:!0};a.a.oa={bits:48,be:!0};a.a.M={bits:64,"float":!0,be:!0};a.a.h=function(a,b){var d=void 0===d?10:d;u(b);var e=[];if(void 0===a)return e;a=A(a,b);return c([a],b,d)};a.a.f=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.ca=function(a,b,d){d=void 0===d?10: +d;u(b);if(b["char"])for(var e=a.length,p=0;p>>0;return this.c(this.j(b))};e.prototype.write=function(a,d,c){c=void 0===c?0:c;d=this.c(d);a[c++]=d&255;for(var b=2;b<=this.offset;b++)a[c++]=Math.floor(d/Math.pow(2,8*(b-1)))&255;return c};e.prototype.C=function(a,d,c){d=this.c(d);c=this.o(a,d,void 0===c?0:c);for(var b=2;bthis.b?1:Math.ceil(this.g/8);if(this.g!=this.b||8>this.b||32this.max&&(a-=2*this.max+2);return a};e.prototype.c=function(a){a>this.max?a=this.max:athis.b||64this.b?a[c++]=0>d?d+Math.pow(2,this.b):d:a[c++]=d&255;return c};a.a=e}]); \ No newline at end of file diff --git a/docs/global.html b/docs/global.html index 154a566..f2c670e 100644 --- a/docs/global.html +++ b/docs/global.html @@ -479,7 +479,7 @@
Returns:

- Documentation generated by JSDoc 3.5.5 on Sun May 13 2018 23:30:47 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Mon Jun 11 2018 01:48:14 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/docs/index.html b/docs/index.html index b7e1f21..e091c56 100644 --- a/docs/index.html +++ b/docs/index.html @@ -105,7 +105,7 @@

riffChunks.write()


 
 
- Documentation generated by JSDoc 3.5.5 on Sun May 13 2018 23:30:47 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Mon Jun 11 2018 01:48:14 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/docs/index.js.html b/docs/index.js.html index b943057..c96a6c3 100644 --- a/docs/index.js.html +++ b/docs/index.js.html @@ -120,10 +120,11 @@

index.js

*/ function getSubChunks_(buffer) { let chunks = []; - let i = fixIndex_(buffer, 12); + let i = 12; while(i <= buffer.length - 8) { chunks.push(getSubChunk_(buffer, i)); i += 8 + chunks[chunks.length - 1]["chunkSize"]; + i = i % 2 ? i + 1 : i; } return chunks; } @@ -136,7 +137,6 @@

index.js

* @private */ function getSubChunk_(buffer, index) { - index = fixIndex_(buffer, index); let chunk = { "chunkId": getChunkId_(buffer, index), "chunkSize": getChunkSize_(buffer, index), @@ -146,28 +146,13 @@

index.js

buffer.slice(index + 8, index + 12), fourCC_); chunk["subChunks"] = getSubChunks_(buffer.slice(index)); } else { + let slc = chunk["chunkSize"] % 2 ? chunk["chunkSize"] + 1 : chunk["chunkSize"]; chunk["chunkData"] = buffer.slice( - index + 8, index + 8 + chunk["chunkSize"]); + index + 8, index + 8 + slc); } return chunk; } -/** - * Fix the index for reading the chunkId for files - * with broken size descriptions. - * @param {!Uint8Array|!Array<number>} buffer The buffer. - * @param {number} i The start index of the chunk. - * @return {number} The new index. - * @private - */ -function fixIndex_(buffer, i) { - while (buffer[i] == 0 || buffer[i+1] == 0 || - buffer[i+2] == 0 || buffer[i+3] == 0) { - i++; - } - return i; -} - /** * Return the fourCC_ of a chunk. * @param {!Uint8Array|!Array<number>} buffer the RIFF file bytes. @@ -204,7 +189,7 @@

index.js


- Documentation generated by JSDoc 3.5.5 on Sun May 13 2018 23:30:47 GMT-0300 (Hora oficial do Brasil) using the docdash theme. + Documentation generated by JSDoc 3.5.5 on Mon Jun 11 2018 01:48:14 GMT-0300 (Hora oficial do Brasil) using the docdash theme.
diff --git a/index.js b/index.js index 7f766c6..c0f6fa8 100644 --- a/index.js +++ b/index.js @@ -81,10 +81,11 @@ function writeSubChunks_(chunks) { */ function getSubChunks_(buffer) { let chunks = []; - let i = fixIndex_(buffer, 12); + let i = 12; while(i <= buffer.length - 8) { chunks.push(getSubChunk_(buffer, i)); i += 8 + chunks[chunks.length - 1]["chunkSize"]; + i = i % 2 ? i + 1 : i; } return chunks; } @@ -97,7 +98,6 @@ function getSubChunks_(buffer) { * @private */ function getSubChunk_(buffer, index) { - index = fixIndex_(buffer, index); let chunk = { "chunkId": getChunkId_(buffer, index), "chunkSize": getChunkSize_(buffer, index), @@ -107,28 +107,13 @@ function getSubChunk_(buffer, index) { buffer.slice(index + 8, index + 12), fourCC_); chunk["subChunks"] = getSubChunks_(buffer.slice(index)); } else { + let slc = chunk["chunkSize"] % 2 ? chunk["chunkSize"] + 1 : chunk["chunkSize"]; chunk["chunkData"] = buffer.slice( - index + 8, index + 8 + chunk["chunkSize"]); + index + 8, index + 8 + slc); } return chunk; } -/** - * Fix the index for reading the chunkId for files - * with broken size descriptions. - * @param {!Uint8Array|!Array} buffer The buffer. - * @param {number} i The start index of the chunk. - * @return {number} The new index. - * @private - */ -function fixIndex_(buffer, i) { - while (buffer[i] == 0 || buffer[i+1] == 0 || - buffer[i+2] == 0 || buffer[i+3] == 0) { - i++; - } - return i; -} - /** * Return the fourCC_ of a chunk. * @param {!Uint8Array|!Array} buffer the RIFF file bytes. diff --git a/package.json b/package.json index c559d3d..270275d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "riff-chunks", - "version": "4.0.5", + "version": "4.0.6", "description": "Read and write the chunks of RIFF and RIFX files.", "homepage": "https://github.com/rochars/riff-chunks", "author": "Rafael da Silva Rocha ",