blkdat-stream

    1.0.2 • Public • Published

    blkdat-stream

    A lite blk*.dat streaming module, useful for parsing the Bitcoin blockchain

    Example

     
    var fs = require('fs')
    var glob = require('glob')
     
    var CombinedStream = require('combined-stream')
    var BlkDatStream = require('../')
     
    glob(process.env.BLOCKS_DIR + '/blk*.dat', function (err, fileNames) {
      if (err) throw err
     
      var cs = new CombinedStream()
     
      fileNames.forEach(function(fileName) {
        cs.append(fs.createReadStream(fileName, { mode: '0444' }))
      })
     
      var bds = new BlkDatStream()
      var j = 0
      bds.on('data', function(blockData) {
        console.log('>> Read block (', j, ')')
        j++
     
        // ... now, parse the block data buffer
      })
     
      cs.pipe(bds)
    })

    To parse the returned block data, use a library such as bitcoinjs-lib or bitcore

    Install

    npm i blkdat-stream

    DownloadsWeekly Downloads

    28

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • junderw
    • fanatid
    • jprichardson