close stream when convert to array

Fix issue #148 which causing `Too many open files`. See #148 for details explanation.