You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

25 lines
719 B

var Block = require('../lib/block');
var BufferReader = require('../lib/bufferreader');
var BufferWriter = require('../lib/bufferwriter');
//This example will parse the blocks in a block file.
//To use, pipe in a blk*****.dat file. e.g.:
//cat blk00000.dat | node blockreader.js
var head = null;
process.stdin.on('readable', function() {
if (!head) {
head = process.stdin.read(8);
if (!head)
return;
}
var body = process.stdin.read(head.slice(4).readUInt32LE(0));
if (!body)
return;
var blockbuf = BufferWriter().write(head).write(body).concat();
var block = Block().fromBuffer(blockbuf);
console.log(block.toJSON());
head = null;
process.stdin.unshift(process.stdin.read());
});