See MementoFileWriterSync for a simpler implementation.