value)) { print( '_CLITOR_IS_ not found' . PHP_EOL ); exit; } // Merge content data $chain = []; foreach ( (array) _exec( $argv[1], sprintf( 'keva_filter %s "\d+"', $argv[2] ) ) as $piece) { if ( !isset($piece->key) || !isset($piece->value) || !isset($piece->height) ) { print( 'please wait for all pieces sending complete!' . PHP_EOL ); exit; } // Keep all key versions in memory $chain[$piece->key][$piece->height] = $piece->value; print_r( $piece ); } // Select last piece value by it max block height // // piece could have many of versions (with same key) // this feature related to data reading correction after recovery #1 $pieces = []; foreach ($chain as $key => $height) { ksort( $height ); $pieces[$key] = $height [ array_key_last( $height ) ]; } ksort( $pieces ); // Save file to destination file_put_contents( $argv[3], base64_decode( implode('', $pieces) ) ); printf( 'namespace "%s" saved to "%s"' . PHP_EOL, $argv[2], $argv[3] );