Refactor and breaking change to documents API.

Made things more stream oriented rather than just shoving strings
around. Hopefully this will help the pipeline changes feel at home.