Call file.size only once and only if necessary

Discovered while profiling (using Chrome) that the file.size property is expensive. This code change optimizes performance by only accessing the 'size' property once and only if needed.
Merge pull request #2722 from dougdomeny/patch-1

Call file.size only once and only if necessary