getting the file system encoding is loop invariant

so move it out of the loop.