<commit_before>#!/usr/bin/env node

var Dissolve = require("./index");

var parser = Dissolve().loop(function(end) {
  var i = 0;
  this.uint8("id").uint8("data_len").loop("data", function(end) {
    if (i++ >= this.vars.data_len) {
      return end(true);
    }

    this.uint8("a").uint8("b");
  }).tap(function() {
    this.emit("data", this.vars);
    this.vars = Object.create(null);
  });
});

parser.on("data", function(e) {
  console.log(e);
});

parser.write(new Buffer([0x01, 0x03, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06]));
<commit_msg>made the loop example a bit more useful<commit_after>#!/usr/bin/env node

var Dissolve = require("./index");

var parser = Dissolve().loop(function(end) {
  this.uint8("id").loop("data", function(end) {
    this.uint8("type").tap(function() {
      if (this.vars.type === 0) {
        return end(true);
      }

      this.uint8("x").uint8("y");
    });
  }).tap(function() {
    this.emit("data", this.vars);
    this.vars = Object.create(null);
  });
});

parser.on("data", function(e) {
  console.log(e);
});

parser.write(new Buffer([0x01, 0x01, 0x11, 0x12, 0x01, 0x21, 0x22, 0x01, 0x31, 0x32, 0x00]));

{'fraction_non_alphanumeric': 0.22434782608695653, 'fraction_numerical': 0.058260869565217394, 'mean_word_length': 3.6224899598393576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5062617', 'n_tokens_mistral': 501, 'n_tokens_neox': 451, 'n_words': 80}