PHP Classes

File: dumpindex.php

Recommend this page to a friend!
  Classes of Rodrigo Faustino   Blockchain PHP Script   dumpindex.php   Download  
File: dumpindex.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Blockchain PHP Script
Examples to show how to manipulate a blockchain
Author: By
Last change:
Date: 6 months ago
Size: 599 bytes
 

Contents

Class file image Download
<?php
/**
 * dumpindex
 *
 * Dumps all of the records in a blockchain index.
 *
 * Marty Anstey (https://marty.anstey.ca/)
 * August 2015
 *
 */
define('_fn', 'blockchain.dat.idx');

if (!
file_exists(_fn)) exit("Can't open "._fn);
$fp = fopen(_fn,'rb');
$records = unpack('V', fread($fp, 4))[1];

for (
$i=0;$i<$records;$i++) {
   
$ofs = unpack('V', fread($fp, 4))[1];
   
$len = unpack('V', fread($fp, 4))[1];
    print
str_pad($i,5,' ',STR_PAD_RIGHT)."OFS: ".str_pad($ofs,8,' ',STR_PAD_RIGHT)." LEN: $len\n";
}

fclose($fp);

function
unpack32($data,$ofs) {
    return
unpack('V', substr($data,$ofs,4))[1];
}