foliojs/restructure

README example not working?

mathiasbynens opened this issue · 2 comments

This example is taken from the README:

var fs = require('fs');
var r = require('restructure');

var Person = new r.Struct({
  name: r.String(r.uint8, 'utf8'),
  age: r.uint8
});

var stream = new r.EncodeStream();
stream.pipe(fs.createWriteStream('out.bin'));

Person.encode(stream, {
  name: 'Devon',
  age: 21
});

stream.end();

Running it in various io.js/Node.js versions throws:

/tmp/restructure-test/node_modules/restructure/src/Struct.js:77
        if (type.size != null) {
                ^
TypeError: Cannot read property 'size' of undefined
    at Struct.size (/tmp/restructure-test/node_modules/restructure/src/Struct.js:77:17)
    at Struct.encode (/tmp/restructure-test/node_modules/restructure/src/Struct.js:99:45)
    at Object.<anonymous> (/tmp/restructure-test/x.js:12:8)
    at Module._compile (module.js:426:26)
    at Object.Module._extensions..js (module.js:444:10)
    at Module.load (module.js:351:32)
    at Function.Module._load (module.js:306:12)
    at Function.Module.runMain (module.js:467:10)
    at startup (node.js:117:18)
    at node.js:946:3

That should read new r.String(r.uint8, 'utf8').

Ah, that makes sense. I’ll submit a PR.