anchor.diff:          Padding = <<0:(8*(?SIZE_BLOCK-BlockOffset))>>
       end,
       FinalBin = [Padding, <<1, BinSize:32/integer>> | make_blocks(5, [Bin])],
  -    {reply, file:write(Fd, FinalBin), File};
  -
  -handle_call(find_header, _From, #file{fd = Fd} = File) ->
  -    {ok, Pos} = file:position(Fd, eof),
  +    case file:write(Fd, FinalBin) of
  +    ok ->
  +        {reply, ok, File#file{eof = Pos + iolist_size(FinalBin)}};
  +    Error ->
  +        {reply, Error, File}
  +    end;
  +
  +handle_call(find_header, _From, #file{fd = Fd, eof = Pos} = File) ->
       {reply, find_header(Fd, Pos div ?SIZE_BLOCK), File}.
   
   handle_cast(close, Fd) ->
  
positive.code: 
  handle_call({truncate, Pos}, _From, #file{fd=Fd}=File) ->
      {ok, Pos} = file:position(Fd, Pos),
      {reply, file:truncate(Fd), File};
  
  handle_call({append_bin, Bin}, _From, #file{fd = Fd} = File) ->
      {ok, Pos} = file:position(Fd, eof),
      Blocks = make_blocks(Pos rem ?SIZE_BLOCK, Bin),
      case file:write(Fd, Blocks) of
      ok ->
          {reply, {ok, Pos}, File};
      Error ->
          {reply, Error, File}
      end;
  
  handle_call({write_header, Bin}, _From, #file{fd = Fd} = File) ->
      {ok, Pos} = file:position(Fd, eof),
      BinSize = byte_size(Bin),
      case Pos rem ?SIZE_BLOCK of
      0 ->
  
negative.code: -define(SIZE_BLOCK, 4096).
  
  -record(file, {
      fd,
      eof = 0
  }).
  
  % public API
  