split.js 846 B

12345678910111213141516171819202122232425262728293031323334
  1. var binary = require('../');
  2. var test = require('tap').test;
  3. var EventEmitter = require('events').EventEmitter;
  4. test('split', function (t) {
  5. t.plan(1);
  6. var em = new EventEmitter;
  7. binary.stream(em)
  8. .word8('a')
  9. .word16be('bc')
  10. .word32ls('x')
  11. .word32bs('y')
  12. .tap(function (vars) {
  13. t.same(vars, {
  14. a : 97,
  15. bc : 25187,
  16. x : 621609828,
  17. y : 621609828,
  18. });
  19. })
  20. ;
  21. em.emit('data', new Buffer([ 97, 98 ]));
  22. setTimeout(function () {
  23. em.emit('data', new Buffer([ 99, 100 ]));
  24. }, 25);
  25. setTimeout(function () {
  26. em.emit('data', new Buffer([ 3, 13, 37, 37 ]));
  27. }, 30);
  28. setTimeout(function () {
  29. em.emit('data', new Buffer([ 13, 3, 100 ]));
  30. }, 40);
  31. });