3 var utils = require('./utils');
6 * An object to write any content to an Uint8Array.
8 * @param {number} length The length of the array.
10 var Uint8ArrayWriter = function(length) {
11 this.data = new Uint8Array(length);
14 Uint8ArrayWriter.prototype = {
16 * Append any content to the current array.
17 * @param {Object} input the content to add.
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;
28 * Finalize the construction an return the result.
29 * @return {Uint8Array} the generated array.
31 finalize: function() {
36 module.exports = Uint8ArrayWriter;