Properly encode file names from S3

Resolves #111
This code is pretty strange, so warrants a more detailed comment describing exactly why we're doing this.