implement sync_and_close

Signed-off-by: Janos Laube <janos.dev@gmail.com>