Sounds like you tried to read a multi-GB file completely into memory.
Adam Cameron recently posted a similar instance and shows how reading the data in bits might be a better solution:
http://cfmlblog.adamcameron.me/2013/12/file-looping-strategies-it-does nt-seem.html