anchor.diff:  	loop(Writer,[],true,0,0,Stream).
   
   loop(Writer,DataList,ClearToSend,LastTS,Count,StreamName) ->
  -        case length(DataList) > 0 of
  -		true ->
  -                        case ClearToSend of
  -				true ->
  -					lager:debug("Now clear to send - sending what we have..."),
  -					Writer ! {Count,LastTS,lists:reverse(DataList)},
  -					loop(Writer,[],false,LastTS,0,StreamName);
  -				false ->
  -					lager:debug("Have data, waiting for clear to send")
  -			end;
  -		false ->
  -                        lager:debug("Have no data, listening")
  -	end,	
   	receive
   		Message ->
   			case Message of 
  
positive.code: 	 case file:read(DataFile,3) of
      	{ok,<<3,3,3>>} -> lager:info("Last message found at ~p in ~p, truncating file...",[Offset,FileName]),
      					  file:truncate(DataFile);
      	_Data          -> fix_file(DataFile,NewOffset,FileName)
      end.
  
  
  
negative.code: 	after 5000 ->
  		% Routine maintenance 
  		erlang:garbage_collect(),
  		case ClearToSend of
  			true ->
  				case length(DataList) > 0 of
  					true ->
  						lager:debug("Clear to send but no new data in the last 5 seconds - sending what we have..."),
  						Writer ! {Count,LastTS,lists:reverse(DataList)},
  						loop(Writer,[],false,LastTS,0,StreamName);
  					false ->
  						lager:debug("Clear to send but no data..."),
  						loop(Writer,[],true,LastTS,Count,StreamName)
  				end;
  			false ->
  				loop(Writer,DataList,false,LastTS,Count,StreamName)
  		end	
  	end.
  
  
  