Ingen beskrivning

StringReader.js 1020B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var DataReader = require('./DataReader');
  3. var utils = require('../utils');
  4. function StringReader(data) {
  5. DataReader.call(this, data);
  6. }
  7. utils.inherits(StringReader, DataReader);
  8. /**
  9. * @see DataReader.byteAt
  10. */
  11. StringReader.prototype.byteAt = function(i) {
  12. return this.data.charCodeAt(this.zero + i);
  13. };
  14. /**
  15. * @see DataReader.lastIndexOfSignature
  16. */
  17. StringReader.prototype.lastIndexOfSignature = function(sig) {
  18. return this.data.lastIndexOf(sig) - this.zero;
  19. };
  20. /**
  21. * @see DataReader.readAndCheckSignature
  22. */
  23. StringReader.prototype.readAndCheckSignature = function (sig) {
  24. var data = this.readData(4);
  25. return sig === data;
  26. };
  27. /**
  28. * @see DataReader.readData
  29. */
  30. StringReader.prototype.readData = function(size) {
  31. this.checkOffset(size);
  32. // this will work because the constructor applied the "& 0xff" mask.
  33. var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
  34. this.index += size;
  35. return result;
  36. };
  37. module.exports = StringReader;