rewrote writing streams

    return a stream to write to instead of passing a stream in
    that way the caller can control the piping and does not need to
    buffer anything.

    the returned stream emits 'close' when the underlying file stream
    does

    the returned stream triggers writing the package reference
    when the last chunk was written