UI for Zipcoin Blue

json_parser.js 650B

12345678910111213141516171819202122232425262728293031
  1. if (global.GENTLY) require = GENTLY.hijack(require);
  2. var Buffer = require('buffer').Buffer;
  3. function JSONParser(parent) {
  4. this.parent = parent;
  5. this.chunks = [];
  6. this.bytesWritten = 0;
  7. }
  8. exports.JSONParser = JSONParser;
  9. JSONParser.prototype.write = function(buffer) {
  10. this.bytesWritten += buffer.length;
  11. this.chunks.push(buffer);
  12. return buffer.length;
  13. };
  14. JSONParser.prototype.end = function() {
  15. try {
  16. var fields = JSON.parse(Buffer.concat(this.chunks));
  17. for (var field in fields) {
  18. this.onField(field, fields[field]);
  19. }
  20. } catch (e) {
  21. this.parent.emit('error', e);
  22. }
  23. this.data = null;
  24. this.onEnd();
  25. };