Add the stream class

@nelhage, if this looks reasonable I'll start writing some tests.