uint8ArrayReader.js 721 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var ArrayReader = require('./arrayReader');
  3. function Uint8ArrayReader(data) {
  4. if (data) {
  5. this.data = data;
  6. this.length = this.data.length;
  7. this.index = 0;
  8. this.zero = 0;
  9. }
  10. }
  11. Uint8ArrayReader.prototype = new ArrayReader();
  12. /**
  13. * @see DataReader.readData
  14. */
  15. Uint8ArrayReader.prototype.readData = function(size) {
  16. this.checkOffset(size);
  17. if(size === 0) {
  18. // in IE10, when using subarray(idx, idx), we get the array [0x00] instead of [].
  19. return new Uint8Array(0);
  20. }
  21. var result = this.data.subarray(this.zero + this.index, this.zero + this.index + size);
  22. this.index += size;
  23. return result;
  24. };
  25. module.exports = Uint8ArrayReader;