copying arrayedstream implementation from Picturase

https://picturase.codeplex.com/