Add arg-sample code

@mjhubisz

This PR addresses issue #9 by merging the code needed for `arg-sample` into master.

Also, this PR replaces #5.

It might help to remove the flushing in order speed up writing a little bit.