this is untested, you can help by testing it
maybe iteration would also be nice, but then it'd be better to keep the file handle open? idk