Changed the stream closing API to return a promise for the total length.