Update JSON API
[src/app-framework-demo.git] / afm-client / bower_components / jszip / lib / uint8ArrayWriter.js
1 'use strict';
2
3 var utils = require('./utils');
4
5 /**
6  * An object to write any content to an Uint8Array.
7  * @constructor
8  * @param {number} length The length of the array.
9  */
10 var Uint8ArrayWriter = function(length) {
11     this.data = new Uint8Array(length);
12     this.index = 0;
13 };
14 Uint8ArrayWriter.prototype = {
15     /**
16      * Append any content to the current array.
17      * @param {Object} input the content to add.
18      */
19     append: function(input) {
20         if (input.length !== 0) {
21             // with an empty Uint8Array, Opera fails with a "Offset larger than array size"
22             input = utils.transformTo("uint8array", input);
23             this.data.set(input, this.index);
24             this.index += input.length;
25         }
26     },
27     /**
28      * Finalize the construction an return the result.
29      * @return {Uint8Array} the generated array.
30      */
31     finalize: function() {
32         return this.data;
33     }
34 };
35
36 module.exports = Uint8ArrayWriter;